Manish Solanki

Manish Solanki

  • 2k
  • 77
  • 21.4k

send mail in Microsoft Office Outlook

Sep 23 2015 3:38 AM
Hello Everyone,
                 I have to send mail from one static id to microsoft office  outlook.i will send code of my .please help me
sending id="xyx@xyz.com"; 
to:"yyy@yyy.com";
 
 
public Outlook.Account GetAccountForEmailAddress(Outlook.Application application, string smtpAddress)
{
// Loop over the Accounts collection of the current Outlook session.
Outlook.Accounts accounts = application.Session.Accounts;
foreach (Outlook.Account account in accounts)
{
// When the e-mail address matches, return the account.
if (account.SmtpAddress == "xyx@xyz.com")
{
return account;
}
}
throw new System.Exception(string.Format("No Account with SmtpAddress: {0} exists!", smtpAddress));
}
 
 
Outlook.Application oApp = new Outlook.Application();
Outlook._NameSpace oNamespace;
Outlook.MAPIFolder oOutbox;
oNamespace = oApp.GetNamespace("MAPI");
oNamespace.Logon(null, null, true, true);
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
oMsg.Subject = "Sign In......!";
oMsg.To = "yyy@yyy.com";
Outlook.Account account = GetAccountForEmailAddress(oApp,"xyx@xyz.com");
oMsg.SendUsingAccount = account
oMsg.Send();
oMsg = null;
oApp = null;
 
 i want to send mail from xyx@xyz.com this id.
to anyone
i hope you will send me help in code 

Answers (16)