/// <summary> /// Adds an email to MS Outlook Outbox /// </summary> /// <param name="toValue">Email address of recipient</param> /// <param name="asunto">Email subject</param> /// <param name="cuerpo">Email body</param> public void addToOutBox(string toValue, string asunto, string cuerpo, List <string> archivosAdjuntos) { //creates a new MailItem object Microsoft.Office.Interop.Outlook._MailItem oMailItem = (Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem); oMailItem.To = toValue; oMailItem.Subject = asunto; oMailItem.HTMLBody = cuerpo; foreach (string adjunto in archivosAdjuntos) { oMailItem.Attachments.Add(adjunto); } //oMailItem.SaveSentMessageFolder = oOutboxFolder; Microsoft.Office.Interop.Outlook.Accounts accounts = oApp.Session.Accounts; foreach (Microsoft.Office.Interop.Outlook.Account account in accounts) { string address = account.SmtpAddress; if (address == _cuenta) { oMailItem.SendUsingAccount = account; } } //uncomment this to also save this in your draft //oMailItem.Save(); //adds it to the outbox oMailItem.Send(); }
public MainForm() { InitializeComponent(); this.client = new ModeratorClient(Properties.Settings.Default.ContentModerator_SubscriptionKey); webBody.ScriptErrorsSuppressed = true; outlookApp = new Microsoft.Office.Interop.Outlook.Application(); outlookNamespace = outlookApp.GetNamespace("MAPI"); accounts = outlookApp.Session.Accounts; foreach (Microsoft.Office.Interop.Outlook.Account account in accounts) { toolStripComboBox_Accounts.Items.Add(account.DisplayName); } if (accountsExist()) { toolStripComboBox_Accounts.SelectedIndex = 0; } }