Click here to Skip to main content
15,881,173 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo!

I have a strange problem and would highly appreciate any help!
I am sending an email like this:

C#
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace oNameSpace = oApp.GetNamespace("MAPI");
Microsoft.Office.Interop.Outlook.MAPIFolder oFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderSentMail);
Microsoft.Office.Interop.Outlook.MailItem oItem = oFolder.Items.Add(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
Ol.Accounts accs = oNameSpace.Accounts;

string sEmailText = = "This is a stupid dummy text.\nIt is here to test if sending stupid emails even with a dummy text is not possible correctly!\n\nIn Love\nyour cookie!";
				
oItem.To = receiver[0];
oItem.Subject = "test"  
oItem.Body = sEmailText;

for (int i = 1; i <= accs.Count; i++)
{
     Ol.Account acc = accs[i];
}
				
oItem.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText;
oItem.Send();


In oItem.Body the email looks perfectly right. But when I receive the email in my Outlook the text is the following:

This is a stupid dummy text.
It is here to test if sending stupid emails even with a dummy text is not possible correctly!

In Love
your cookie!

<HTML>This is a stupid dummy text.
It is here to test if sending stupid emails even with a dummy text is not possible correctly!

In Love
your cookie!


I tried my very best but I just cannot make out any failure... Maybe anyone could help?
Thank you very very much!

Tom

edit:
Maybe it is also important to tell you that the email text is not always doubled like above. Sometimes it is just a piece of the original text, that is added to the correct mail.
Posted
Updated 18-Mar-13 1:56am
v2

Hello.

Here[^] is aMS Support article showing how to send email via outlooik. The major difference I can see between your code and MS support code is, how the message gets created. May be following code wrok's correctly for you.
C#
Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

Outlook.Recipient oRecip = (Outlook.Recipient) oMsg.Recipients.Add(receiver[0]);
oRecip.Resolve();

oMsg.Subject = "test";
oMsg.Body = "This is a stupid dummy text.\nIt is here to test if sending stupid emails even with a dummy text is not possible correctly!\n\nIn Love\nyour cookie!";
oMsg.Save();
oMsg.Send();


Regards,
 
Share this answer
 
v3
Comments
Prasad_Kulkarni 18-Mar-13 10:01am    
5'ed! :D
Tieftontier 19-Mar-13 2:15am    
Thanks a lot! Did not try this, because Solution 3 which is faster to change worked for me :-)
Try setting the _MailItem.BodyFormat Property[^] to olFormatPlain.
 
Share this answer
 
Comments
Tieftontier 19-Mar-13 2:14am    
Thank you very much! So simple, but it helped... Thought that I already tried that, but you know how it is: I did not^^
Richard MacCutchan 19-Mar-13 5:13am    
Ah, we have all done that from time to time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900