public string OutLookEventMail(eMail mail) { try { Application outlookapp = new Application(); MailItem mailitem = (MailItem)outlookapp.CreateItem(OlItemType.olMailItem); if (mailitem != null) { mailitem.BodyFormat = mail.mailformat; mailitem.Subject = mail.Subject; mailitem.Body = mail.Body; Recipient recipient = null; foreach (var receipient in mail.Receipients) { recipient = mailitem.Recipients.Add(receipient); } try { mailitem.Send(); return("Success"); } catch (System.Exception ex) { return("Fail"); } } } catch (System.Exception ex) { } return(string.Empty); }
public static void SendEmailWithOutlook(MailModel mailModel) { try { OutlookApp outlookApp = new OutlookApp(); MailItem mailItem = outlookApp.CreateItem(OlItemType.olMailItem); mailItem.To = mailModel.Recipient; mailItem.Subject = mailModel.Subject; if (mailModel.IsHtmlBody) { mailItem.HTMLBody = mailModel.Body; } else { mailItem.Body = mailModel.Body; } mailItem.Send(); MessageBox.Show("Mail erfolgreich übermittelt", "Email-Versand"); } catch (System.Exception exp) { MessageBox.Show( $"Das E-Mail konnte nicht übermittelt werden.\n\nBitte nehmen Sie mit dem Entwickler Kontakt auf.\n\n Fehler : {exp.Message}", "Fehler beim Mailversand", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { // init args, can get from config, args or hard code. String filename = "C:\\Users\\spamish\\Documents\\Personal.xlsb"; MailAddress recipient = new MailAddress("*****@*****.**"); String subject = "Test email"; // error checking here if (!File.Exists(filename)) { throw new FileNotFoundException(); } // start application and build new email Application app = new Application(); MailItem mail = (MailItem)app.CreateItem(OlItemType.olMailItem); mail.Attachments.Add(filename); mail.To = recipient.Address; mail.Subject = subject; // Send email, then send and receive all new mail. mail.Send(); app.Session.SendAndReceive(false); app.Quit(); }
public static void ReplyTo(MailMessage message, string body, List <string> attachments, bool replyAll, CancellationToken ct) { Application application = null; MailItem mailItem = null; MailItem mailItem2 = null; ct.ThrowIfCancellationRequested(); application = InitOutlook(); using (application.DisposeWithReleaseComObject()) { NameSpace @namespace = application.GetNamespace("MAPI"); string text = message.Headers["Uid"]; if (string.IsNullOrEmpty(text)) { throw new ArgumentException("非法的邮件对象!"); } mailItem = (dynamic)@namespace.GetItemFromID(text, Type.Missing); using (mailItem.DisposeWithReleaseComObject()) { mailItem2 = (replyAll ? mailItem.ReplyAll() : mailItem.Reply()); } using (mailItem2.DisposeWithReleaseComObject()) { foreach (string attachment in attachments) { ct.ThrowIfCancellationRequested(); mailItem2.Attachments.Add(attachment, Type.Missing, Type.Missing, Type.Missing); } mailItem2.HTMLBody = body + mailItem2.HTMLBody; mailItem2.BodyFormat = OlBodyFormat.olFormatHTML; ct.ThrowIfCancellationRequested(); mailItem2.Send(); } } }
//************************************************************************************************ public static response toSendEmail(string strCorreo, string strAsunto, string strCuerpo, string path) { var resultado = new response(); try { var oApp = new Microsoft.Office.Interop.Outlook.Application(); MailItem oMsg = default(MailItem); oMsg = (MailItem)oApp.CreateItem(OlItemType.olMailItem); oMsg.Subject = strAsunto; oMsg.HTMLBody = strCuerpo; oMsg.To = strCorreo.Trim(); if (!string.IsNullOrEmpty(path)) { oMsg.Attachments.Add(path); } //oMsg.CC = Trim(StrCorreoOp) oMsg.Send(); oApp = null; oMsg = null; resultado.Exito = true; resultado.MensajeError = "Se ha enviado correctamente el correo."; //***************************************************************************** } catch (Exception ex) { resultado.Exito = false; resultado.MensajeError = ex.Message; } return(resultado); }
public void SendEmail(string[] recipients, string body, string subject, string attachment, string attachmentname) { Console.WriteLine("[+] Sending an e-mail.\r\nRecipients: {0}\r\nSubject: {1}\r\nAttachment Path: {2}\r\nAttachment Name: {3}\r\nBody: {4}", String.Join(",", recipients), subject, attachment, attachmentname, body); try { Application outlookApplication = new Application(); MailItem msg = (MailItem)outlookApplication.CreateItem(OlItemType.olMailItem); msg.HTMLBody = body; int pos = msg.Body.Length + 1; int attType = (int)OlAttachmentType.olByValue; Attachment attach = msg.Attachments.Add(attachment, attType, pos, attachmentname); msg.Subject = subject; foreach (var recipient in recipients) { Recipients recips = msg.Recipients; Recipient recip = recips.Add(recipient); recip.Resolve(); } msg.Send(); Console.WriteLine("[+] Message Sent"); } catch (Exception e) { Console.WriteLine(e.Message); } }
private void SendAndDispose(List <MailItem> phishEmails) { MailItem reportEmail = null; try { reportEmail = (MailItem)Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem); foreach (var phishEmail in phishEmails) { reportEmail.Attachments.Add(phishEmail, OlAttachmentType.olEmbeddeditem); } reportEmail.Subject = Config.ReportingEmailSubject.Replace("$PluginName$", AppInfo.ApplicationProduct); reportEmail.To = Config.SecurityTeamEmail; reportEmail.Body = _reportEmailBody; reportEmail.Send(); foreach (var phishEmail in phishEmails) { phishEmail.Delete(); } } finally { reportEmail.Dispose(); foreach (var phishEmail in phishEmails) { phishEmail.Dispose(); } } }
protected void Button1_Click1(object sender, EventArgs e) { string email; email = "*****@*****.**"; Application app = new Application(); MailItem mItem = (MailItem)app.CreateItem(OlItemType.olMailItem); mItem.Subject = "Feedback By User"; mItem.CC = "[email protected];[email protected];[email protected]"; mItem.Body = txtFeedBack.Text; mItem.To = email; mItem.Send(); Response.Write("<script>alert('Thanks For Sending the Response')</script>"); Server.Transfer("Home.aspx"); }
public void SendMail(MailItem mailItem) { if (mailItem.FlagRequest == MailServiceSettings.CopyMailFlag) { MAPIFolder folder = _Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail); mailItem.Move(folder); return; } if (mailItem.FlagRequest != MailServiceSettings.AutoMailFlag) { string to = $"{mailItem.To}; {mailItem.CC}"; Outlook.Folder selectedFolder = StartDialogService(); if (selectedFolder != null) { mailItem.SaveSentMessageFolder = selectedFolder; mailItem.Save(); MailItem copyMail = mailItem.Copy(); copyMail.FlagRequest = MailServiceSettings.CopyMailFlag; copyMail.Save(); SendToRecipients(to); } } mailItem.Send(); }
//protected void LinkButton3_Click(object sender, EventArgs e) //{ // btnEmail1.OnClientClick = "window.location.href = 'mailto:' + [email protected] + '?subject=' + Email Subject3 + '&body=' + ;"; //} public bool SendEmailViaOutLook() { //try //{ // Create a Outlook Application and connect to outlook Application OutlookApplication = new Application(); // create the MailItem which we want to send MailItem message = (MailItem)OutlookApplication.CreateItem(OlItemType.olMailItem); MailAddress toAddress = new MailAddress("*****@*****.**"); MailAddress ccAddress = new MailAddress("*****@*****.**"); message.To = toAddress.ToString(); message.CC = ccAddress.ToString(); message.Subject = "Mail Subject2"; message.Body = "Mail Body2"; message.HTMLBody = getHTML(gridView); message.BodyFormat = OlBodyFormat.olFormatHTML; //Send email message.Send(); return(true); //} //catch (System.Exception ex) //{ // return false; //} }
protected void Button1_Click1(object sender, EventArgs e) { Pool obj = new Pool(); int ret1; string email; email = txtEmployeeId.Text + "@infosys.com"; ret1 = obj.Register(Convert.ToInt32(txtEmployeeId.Text), txtPassw.Text, Convert.ToDouble(txtContact.Text), email, Convert.ToString(rblStatus.SelectedValue), Convert.ToString(ddlSecurityQuestion.SelectedItem), txtAnswer.Text); if (ret1 == 1) { Application app = new Application(); MailItem mItem = (MailItem)app.CreateItem(OlItemType.olMailItem); mItem.Subject = "Successfully Registered"; mItem.Body = "Thanks For Joining Our website "; mItem.To = email; mItem.Send(); Response.Write("<script>alert('You are successfully registered')</script>"); Server.Transfer("Home.aspx"); } else { Response.Write("<script>alert('You are Already registered')</script>"); Server.Transfer("Home.aspx"); } }
protected void btnBooking_Click(object sender, EventArgs e) { Pool obj = new Pool(); int empid; int empid2 = Convert.ToInt32(Session["LogIn"]); //Check That User Can't Book his Own Car. obj.CheckEmpId(Convert.ToString(txtReviewCarId.Text), out empid); if (empid == empid2) { Response.Write("<script>alert('You Cannot Book your Own car')</script>"); Server.Transfer("Home.aspx"); } int ret; int BookingId = 0; Session["FinalStatus"] = Convert.ToString(txtStatus.Text); Session["FinalStoppage"] = Convert.ToString(txtReviewStoppageName.Text); //Check That User Can't Book Same or any Other Car if they already have Active Booking ret = obj.Booking(Convert.ToString(txtReviewCarId.Text), Convert.ToString(txtReviewStoppageName.Text), Convert.ToInt32(Session["LogIn"]), Convert.ToString(txtStatus.Text), Convert.ToDateTime(txtDateStart.Text), Convert.ToDateTime(txtDateEnd.Text), out BookingId); if (BookingId == 0) { Response.Write("<script>alert('You Already have Active Booking so Please Cancel Your Previous Booking')</script>"); Server.Transfer("Home.aspx"); } Session["BookingId"] = BookingId; string CC; CC = Convert.ToString(empid) + "@infosys.com"; string email; // Sending the Email to User or CC to Car Owner. email = Convert.ToString(Session["LogIn"]) + "@infosys.com"; Application app = new Application(); MailItem mItem = (MailItem)app.CreateItem(OlItemType.olMailItem); mItem.Subject = "Booking is Done"; mItem.CC = CC; mItem.Body = "Booking is Done for Car Id : '" + txtReviewCarId.Text + "' and Booking Id is'" + Session["BookingId"] + "'"; mItem.To = email; mItem.Send(); //Generate the Booking Id...... Response.Write("<script>alert('Payment Successful!!Booking Id is " + BookingId + "')</script>"); Server.Transfer("Report.aspx"); }
public void SendMail(string subject, string sender) { Application oApp = new Application(); MailItem mail = oApp.CreateItemFromTemplate(pathFile) as MailItem; mail.To = sender; mail.Subject = subject; mail.Send(); }
private void sendEmail(string name, string email, ref OutlookApp outlookApp) { MailItem mailItem = outlookApp.CreateItemFromTemplate(emailTemplatePath); mailItem.HTMLBody = mailItem.HTMLBody.Replace("%name%", name); mailItem.To = email; mailItem.Send(); }
private void CreateEmailItem(string subjectEmail, string toEmail, string bodyEmail) { MailItem eMail = (MailItem)this.Application.CreateItem(OlItemType.olMailItem); eMail.Subject = subjectEmail; eMail.To = toEmail; eMail.Body = bodyEmail; eMail.Importance = OlImportance.olImportanceLow; eMail.Send(); }
public static void Send_Mail(string to, string subject, string body) { MailItem eMail = ( MailItem )Globals.ThisAddIn.Application.CreateItem(OlItemType.olMailItem); eMail.Subject = subject; eMail.To = to; eMail.Body = body; eMail.Importance = OlImportance.olImportanceHigh; eMail.Send(); }
public void SendFile(string email) { MailItem mail = (MailItem)_outlook.CreateItem(OlItemType.olMailItem); mail.Attachments.Add(FilePath); mail.Subject = Subject; mail.To = email; mail.Send(); _outlook.Quit(); }
public void Send(MailItem mail) { if (mail != null) { mail.Send(); } else { mailItem.Send(); } }
private void Send(GXMailMessage msg) { GXLogging.Debug(log, "Sending Message"); if (session == null) { GXLogging.Error(log, "Could not start Outlook"); throw new GXMailException("Could not start Outlook", 4); } if (editWindow < 0 || editWindow > 1) { GXLogging.Error(log, "Invalid EditWindow value"); throw new GXMailException("Invalid EditWindow value", 28); } if (msg.To.Count == 0) { GXLogging.Error(log, "No main recipient specified"); throw new GXMailException("No main recipient specified", 13); } try { MailItem newMessage = (MailItem)session.CreateItem(OlItemType.olMailItem); newMessage.Subject = msg.Subject; if (msg.Text.Length > 0) { newMessage.Body = msg.Text; } if (msg.HTMLText.Length > 0) { newMessage.HTMLBody = msg.HTMLText; } CopyRecipients(msg.To, newMessage.Recipients, RecipientType.TO); CopyRecipients(msg.CC, newMessage.Recipients, RecipientType.CC); CopyRecipients(msg.BCC, newMessage.Recipients, RecipientType.BCC); CopyAttachments(msg.Attachments, newMessage.Attachments); if ((editWindow == 1) || (!newMessage.Recipients.ResolveAll())) { newMessage.Display(false); } else { newMessage.Send(); } } catch (System.Exception exc) { GXLogging.Error(log, "Could not send message", exc); throw new GXMailException("Could not send message (" + exc.Message + ")", 10); } }
public void SendToRecipients(string to) { MailItem mail = _Application.CreateItem(OlItemType.olMailItem); mail.To = to; mail.Subject = MailServiceSettings.Subject; mail.Body = MailServiceSettings.Body; mail.DeleteAfterSubmit = true; mail.FlagRequest = MailServiceSettings.AutoMailFlag; mail.Send(); }
protected void Button1_Click(object sender, EventArgs e) { string email = TextBox1.Text; using (projectEntities1 context = new projectEntities1()) { var user = (from c in context.Customer_Info where c.Email == email select c).FirstOrDefault(); if (user != null) { string username = user.Customer_Name; string password = user.Customer_Password; Application OutlookApplication = new Application(); MailItem message = (MailItem)OutlookApplication.CreateItem(OlItemType.olMailItem); MailAddress toAddress = new MailAddress(email); message.To = toAddress.ToString(); message.Subject = "Password Recovery"; message.HTMLBody = "Your Username is:" + username + "<br/><br/>" + "Your Password is:" + password; message.BodyFormat = OlBodyFormat.olFormatHTML; message.Send(); //MailMessage msg = new MailMessage(); //msg.From = new MailAddress("mail address"); //msg.To.Add(email); //msg.Subject = " Recover your Password"; //msg.Body = ("Your Username is:" + username + "<br/><br/>" + "Your Password is:" + password); //msg.IsBodyHtml = true; //SmtpClient smt = new SmtpClient(); //smt.Host = "smtp.gmail.com"; //System.Net.NetworkCredential ntwd = new NetworkCredential(); //ntwd.UserName = "******"; //ntwd.Password = "******"; //smt.UseDefaultCredentials = true; //smt.Credentials = ntwd; //smt.Port = 587; //smt.EnableSsl = true; //smt.Send(msg); //Label2.Text = "Username and Password Sent Successfully"; //Label2.ForeColor = System.Drawing.Color.ForestGreen; } } }
public async override Task RunCommand(object sender) { var engine = (IAutomationEngineInstance)sender; var vRecipients = (List <string>) await v_Recipients.EvaluateCode(engine); var vSubject = (string)await v_Subject.EvaluateCode(engine); var vBody = (string)await v_Body.EvaluateCode(engine); Application outlookApp = new Application(); NameSpace test = outlookApp.GetNamespace("MAPI"); test.Logon("", "", false, true); AddressEntry currentUser = outlookApp.Session.CurrentUser.AddressEntry; MailItem mail = (MailItem)outlookApp.CreateItem(OlItemType.olMailItem); if (currentUser.Type == "EX") { currentUser.GetExchangeUser().GetExchangeUserManager(); foreach (var t in vRecipients) { mail.Recipients.Add(t); } mail.Recipients.ResolveAll(); mail.Subject = vSubject; if (v_BodyType == "HTML") { mail.HTMLBody = vBody; } else { mail.Body = vBody; } if (!string.IsNullOrEmpty(v_Attachments)) { var vAttachment = (List <string>) await v_Attachments.EvaluateCode(engine); foreach (var attachment in vAttachment) { mail.Attachments.Add(attachment); } } mail.Send(); } }
/// <summary> /// Email Processing /// </summary> /// <param name="templatePath"></param> /// <param name="subject"></param> /// <param name="toMail"></param> /// <param name="ccMail"></param> /// <param name="bccMail"></param> /// <param name="values"></param> /// <param name="attachFilePaths"></param> /// <param name="sendMail"></param> /// <returns></returns> internal bool EmailFromTemplate( string templatePath, string subject, string toMail, string ccMail, string bccMail, Dictionary <string, string> values, List <string> attachFilePaths, bool sendMail) { try { Folder m_draftFolder = App.Session.GetDefaultFolder( OlDefaultFolders.olFolderDrafts) as Folder; MailItem m_mail = App.CreateItemFromTemplate(templatePath, m_draftFolder) as MailItem; if (m_mail != null) { m_mail.Subject = subject; m_mail.To = toMail; m_mail.CC = ccMail; m_mail.BCC = bccMail; foreach (var x in attachFilePaths) { m_mail.Attachments.Add(x); } // Replace %%%% contents with matches in the body StringBuilder m_sb = new StringBuilder(m_mail.HTMLBody); foreach (var x in values) { m_sb.Replace(string.Format("%%{0}%%", x.Key.ToUpper()), x.Value); } m_mail.HTMLBody = m_sb.ToString(); if (sendMail) { m_mail.Send(); } else { m_mail.Save(); } } return(true); } catch (Exception ex) { // way too lazy to do anything here } return(false); }
public static void SendMail(String to, String cc, String subject, String message) { Application oApp = new Application(); MailItem mailItem = (MailItem)oApp.CreateItem(OlItemType.olMailItem); mailItem.Subject = subject; mailItem.To = to; mailItem.CC = cc; mailItem.Body = message; // mailItem.BodyFormat = OlBodyFormat.olFormatPlain; mailItem.Send(); }
public static void SendEmail(string subjectEmail, string toEmail, string bodyEmail) { MailItem oMsg = app.CreateItem(OlItemType.olMailItem); oMsg.DeleteAfterSubmit = true; //Delete the message from sent box oMsg.Subject = subjectEmail; oMsg.To = toEmail; var ins = oMsg.GetInspector; oMsg.HTMLBody = bodyEmail.Replace("\r\n", "<br />") + oMsg.HTMLBody; //Must append oMsg.HTMLBody to get the default signature oMsg.Send(); }
private void Items_ItemAdd(object Item) { MailItem mailItem = (MailItem)Item; string mails = mailItem.To + mailItem.CC; if (MailServiceSettings.ActiveForEmail.Any(activeMail => mails.Contains(activeMail))) { MailService mailService = new MailService(OutlookApplication); mailService.SendMail(mailItem); return; } mailItem.Send(); }
public static void SendMail(String to, String cc, String subject, String message, String path) { Application oApp = new Application(); MailItem mailItem = (MailItem)oApp.CreateItem(OlItemType.olMailItem); mailItem.Subject = subject; mailItem.To = to; mailItem.CC = cc; Attachment attachmnt = mailItem.Attachments.Add(path, OlAttachmentType.olEmbeddeditem); mailItem.HTMLBody = message; // mailItem.BodyFormat = OlBodyFormat.olFormatPlain; mailItem.Send(); }
public void SendEmail(string sender, string recipient, string subject, string body) { Application app = new Application(); var mapi = app.GetNamespace("MAPI"); mapi.Logon(ShowDialog: false, NewSession: false); var outbox = mapi.GetDefaultFolder(OlDefaultFolders.olFolderOutbox); MailItem email = app.CreateItem(OlItemType.olMailItem); email.To = recipient; email.Subject = subject; email.Body = body; email.Send(); }
public void Send() { var app = new Application(); MailItem mailItem = app.CreateItem(OlItemType.olMailItem); mailItem.Subject = EmailSenderPreferences.EmailSubject; mailItem.To = EmailSenderPreferences.EmailAddress; mailItem.Body = EmailSenderPreferences.EmailMessageBody; var attachedFilePath = CreateExcelDocPreferences.CreatedDocumentDirectory + CreateExcelDocPreferences.CreatedDocumentName; mailItem.Attachments.Add(attachedFilePath); mailItem.Importance = OlImportance.olImportanceHigh; mailItem.Send(); mailItem.Display(false); }
static void Main(string[] args) { Application app = new Application(); var mapi = app.GetNamespace("MAPI"); mapi.Logon(ShowDialog: false, NewSession: false); var outbox = mapi.GetDefaultFolder(OlDefaultFolders.olFolderOutbox); MailItem email = app.CreateItem(OlItemType.olMailItem); email.To = "*****@*****.**"; email.Subject = "Autogenerated email"; email.Body = "This is a test"; email.Send(); // WorkflowInvoker.Invoke(new Workflow1()); }