How to send mail using Microsoft.Office.Interop.Outlook.MailItem by specifying the From address

I use Interop to send email through Outlook, but I cannot provide an email address from.

I want to send emails to multiple users coming from the same sender (from). I need to provide an email address. However, I cannot find the property using Intellisense, which allows me to specify it.

Please, help.

Microsoft.Office.Interop.Outlook.Application olkApp1 = 
    new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem olkMail1 =
    (MailItem)olkApp1.CreateItem(OlItemType.olMailItem);
        olkMail1.To = txtpsnum.Text;
        olkMail1.CC = "";
        olkMail1.Subject = "Assignment note";
        olkMail1.Body = "Assignment note";
        olkMail1.Attachments.Add(AssignNoteFilePath, 
            Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 1, 
                "Assignment_note");
olkMail1.Save();
//olkMail.Send();
+5
source share
2 answers

Outlook . Outlook from , from. , Outlook. :

using Outlook = Microsoft.Office.Interop.Outlook;

Outlook.Accounts accounts = olkApp1.Session.Accounts;
foreach (Outlook.Account account in accounts)
{
    // When the e-mail address matches, send the mail.
    if (account.SmtpAddress == "from@mail.com")
    {
            olkMail1.SendUsingAccount = account;
            ((Outlook._MailItem)olkMail1).Send();
            break;
    }
}
+12

Send , . , SendUsingAccount Account .

var application = new Application();
var mail = (_MailItem) application.CreateItem(OlItemType.olMailItem);
mail.To = "anonymous@somedomain.com";
....
Outlook.Account account = Application.Session.Accounts["MyOtherAccount"];
mailItem.SendUsingAccount = account;
mail.Send();

:

http://msdn.microsoft.com/en-us/library/ff184652.aspx

+5

All Articles