In one of my Outlook addins I need to place my e-mail messages into a specific folder. In my previous post, I’ve write how to create folders in outlook; I’ve do that with no problem; but the creating e-mails… Infact it should be an easy task to perform, just like below :
Outlook.MailItem mailObject = (Outlook.MailItem)myFolder.Items.Add(Outlook.OlItemType.olMailItem); mailObject.Subject = "Subject Of my e-mail"; mailObject.To = "reciever@email.com"; mailObject.Body = "Content of my message"; mailObject.Save();
Its working quite good on paper, but not on my computer. Well, an e-mail message has been created, but outlook did save in into the drafts folder. After a google query (SELECT * FROM GOOGLE 🙂) I’ve found the answer in Microsoft’s news group. It was all about outlook and its way tomake our life easier (!?). It automatically saves newly created e-mail message into dreafts folder. Another strange thing with it is it does not perform the same action for the other type like notes.Anyway, to overcome this problem, I should perform one more task, I should move it to my folder Here is the final code with no problem:
Outlook.MailItem mailObject = (Outlook.MailItem)myFolder.Items.Add(Outlook.OlItemType.olMailItem); mailObject.Subject = "Subject Of my e-mail"; mailObject.To = "reciever@email.com"; mailObject.Body = "Content of my message"; mailObject.Save(); mailObject.Move(myFolder);