How to set the From field programmatically

B

bad_clone

Hi,

I'm creating an Outlook Mail using the following piece of code (C#):

// Creates a new Outlook Application Instance
Outlook.Application outlook = new Outlook.Application();
// Creating a new Outlook Message from the Outlook Application Instance
Outlook.MailItem mic =
(Outlook.MailItem)(outlook.CreateItem(Outlook.OlItemType.olMailItem));
// Assigns the "TO"
mic.To = "(e-mail address removed)";
// Assigns the Subject Field
mic.Subject = subject;
// Define the Mail Message Body. In this example, you can add in HTML
content to the mail message body
mic.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;
mic.HTMLBody = "test";
// Display using Outlook
mic.Display(false);

I would like to know how to set the "From" field. How should I proceed?

I'm using Outlook 12.

Thanks
 
K

Ken Slovak - [MVP - Outlook]

Outlook version?

For Outlook 2007 you can set the sending account, assuming it's a configured
email account in the Outlook profile. Otherwise you'd have to use the
SentOnBehalfOfName property.
 
B

bad_clone

Thanks for your response...

As specified in my initial post, I'm using Outlook version 12 (aka Outlook
2007).

Maybe I should say that I don't want to send an email using a different user
name or anything. Using Outlook itself, I can specify the "From" email
address without using a different account. The email address is a
distribution list, it's not a different account or anything.

I don't want to use the 'SentOnBehalfOfName' property because I don't want
the receiver to see my name.

This works fine with Outlook, I'm just trying to do the same with the Interop.

Thank you
 
K

Ken Slovak - [MVP - Outlook]

Technically when you set the From field in the UI you are setting the
PR_SENT_REPRESENTING_NAME MAPI property, which is shown as the
SentOnBehalfOf property in the Outlook object model.

You can of course try to set the PR_SENT_REPRESENTING_NAME property using
the PropertyAccessor of the MailItem and the DASL property tag
"urn:schemas:httpmail:sendername", or you can use SentOnBehalfOf as I
suggested.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top