Manish Solanki

Manish Solanki

  • NA
  • 77
  • 24.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="[email protected]"; 
 
 
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 == "[email protected]")
{
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 = "[email protected]";
Outlook.Account account = GetAccountForEmailAddress(oApp,"[email protected]");
oMsg.SendUsingAccount = account
oMsg.Send();
oMsg = null;
oApp = null;
 
 i want to send mail from [email protected] this id.
to anyone
i hope you will send me help in code 

Answers (16)