Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Mail Sender Object

Tags:

c#

outlook

I am creating an Email Object in Outlook 2013, but I cannot find how to create the Sender object. I am using this code:

Outlook.MailItem mail = (Outlook.MailItem)
         Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
mail.To = "[email protected]"
mail.Sender = // What goes here?
mail.Subject = "Mail subject";

The Sender object is an implementation of the Outlook.AddressEntry interface, so there must be an implementation somewhere, but where? Is it possible to create this Sender object?

BTW, the sender of the email is not necessary an account registered in Outlook, so I cannot use the mail.SendUsingAccount property for that.

like image 339
Joe Almore Avatar asked Dec 10 '13 22:12

Joe Almore


2 Answers

Thanks to Dmitry Streblechenko on his comments above I could get the answer, and these are the lines to create an AddressEntry and assign it to a Sender:

Outlook.MailItem mail = (Outlook.MailItem) Globals.ThisAddIn.Application.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Recipient recipient = Globals.ThisAddIn.Application.Session.CreateRecipient("[email protected]");
mail.Sender = recipient.AddressEntry;
like image 180
Joe Almore Avatar answered Nov 09 '22 10:11

Joe Almore


You cannot set this property Outlook.MailItem.Sender directly.

Only in cases where there are multiple account configured in the Outlook client, you can set this property to the AddressEntry object of the user that is represented by the CurrentUser property of a specific account.

More Info: See http://msdn.microsoft.com/en-us/library/office/ff869056.aspx

like image 1
Shiva Avatar answered Nov 09 '22 11:11

Shiva