public void Process(DeferredRegistrationArgs args) { Assert.ArgumentNotNull(args, "args"); Assert.ArgumentNotNull(args.MailMessage, "args.MailMessage"); MainUtil.SendMail(args.MailMessage); }
public static void SendEmail(string body, string userEmail) { try { var message = new MailMessage(); var fromAddress = new MailAddress(userEmail, userEmail); message.From = fromAddress; var feedbackRecipients = ConfigurationsUtil.GetRecipients(); if (feedbackRecipients != null) { var arrayFeedbackRecipients = feedbackRecipients.Split(','); foreach (var recipient in arrayFeedbackRecipients) { var toAddress = new MailAddress(recipient, recipient); message.To.Add(toAddress); } } message.Subject = ConfigurationsUtil.GetSubject(); message.SubjectEncoding = Encoding.UTF8; message.IsBodyHtml = true; message.BodyEncoding = Encoding.UTF8; message.Body = body; MainUtil.SendMail(message); } catch (Exception ex) { Log.Error("Send FeedBack Email Message: ", ex, null); } }
private string SendInquiry(Func <Item, MailSetting> generateMailSetting, Func <MailSetting, Dictionary <string, string> > generateMappingTemplate, EnquiryForm form) { string errorMessage = string.Empty; try { var mailSetting = generateMailSetting(Context.Item); var emailMessage = new MailMessage { IsBodyHtml = true, From = new MailAddress(mailSetting.NoReplyEmail), Subject = mailSetting.Subject, Body = mailSetting.EmailTemplateMessage.ReplacePlaceHodler(generateMappingTemplate(mailSetting)) }; emailMessage.To.Add(mailSetting.ReceiverEmail); if (form.UploadFile != null && form.UploadFile.ContentLength > 0) { var attachment = new Attachment(form.UploadFile.InputStream, form.UploadFile.FileName); emailMessage.Attachments.Add(attachment); } if (emailMessage.To.Count > 0) { MainUtil.SendMail(emailMessage); Log.Info($"Sending Mail to: {emailMessage.To}", this); } } catch (Exception ex) { errorMessage = "Some thing go wrong with server"; Log.Error($"Sending Mail Error: {ex.Message}", this); } return(errorMessage); }
/// <summary> /// Composes and sends an email according to user-defined preferences. /// </summary> /// <param name="report">Report to append to email body.</param> /// <param name="item">Item to send information on.</param> /// <param name="sendTo">Receiver's email address.</param> public static void SendEmail(string report, Item item, string sendTo) { MailMessage message = ComposeEmail(report, item, sendTo); if (message == null) { Log.Info("Scheduled Publish: No receiver for publishing email. " + DateTime.Now, new object()); return; } if (NotificationEmailSettings.UseWebConfig) { try { MainUtil.SendMail(message); } catch (Exception ex) { Log.Error(string.Format("{0} {1}", "Scheduled Publish: Sending publish email through web.config settings failed.", ex), message); } } else { SendMailMessage(message); } }
private bool SendMail(string toEmail, string fromEmail, string subject, string body, string attachmentFileName) { var message = new MailMessage { From = new MailAddress(fromEmail), Body = body, Subject = subject, IsBodyHtml = true }; message.To.Add(toEmail); if (attachmentFileName != null && File.Exists(attachmentFileName)) { var attachment = new Attachment(attachmentFileName); message.Attachments.Add(attachment); } try { MainUtil.SendMail(message); Log.Info($"Sent message to {message.To} wth subject {message.Subject}", "SendMailFromTemplate"); return(true); } catch (Exception e) { Log.Error($"Could not send mail message {message.Subject} to {message.To}", e, "SendMailFromTemplate"); return(false); } }
/// <summary> /// Sends the mail. /// </summary> /// <returns>True if the email was sent, false otherwise</returns> protected virtual bool SendMail() { MailMessage message = new MailMessage { From = new MailAddress(this._mailFrom), Body = this._mailBody, Subject = this._mailSubject, IsBodyHtml = true }; message.To.Add(this._mailTo); if (this._mailAttachmentFileName != null && File.Exists(this._mailAttachmentFileName)) { Attachment attachment = new Attachment(this._mailAttachmentFileName); message.Attachments.Add(attachment); } try { MainUtil.SendMail(message); string infoMessage = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.MailSentToMessage); Log.Info(Translate.Text(string.Format(CultureInfo.InvariantCulture, infoMessage, message.To, message.Subject)), "SendMailFromTemplate"); return(true); } catch (Exception e) { string errorMessage = StorefrontManager.GetSystemMessage(StorefrontConstants.SystemMessages.CouldNotSendMailMessageError); Log.Error(Translate.Text(string.Format(CultureInfo.InvariantCulture, errorMessage, message.Subject, message.To)), e, "SendMailFromTemplate"); return(false); } }
private void SendAbortMessage(PublishEndResultBatchArgs args) { MailMessage message = new MailMessage(this.MailFrom, this.MailTo); message.Subject = $"Publishing job {args.JobData.JobId} aborted at {DateTime.Now}"; message.Body = $"A publishing job was just aborted. Job Id: {args.JobData.JobId} \n Message: {args.Message}"; MainUtil.SendMail(message); }
public void SendPassword(string email, string newPassword) { var mail = this._siteSettings.GetForgotPasswordMailTemplate(); mail.To.Add(email); mail.Body = mail.Body.Replace("$password$", newPassword); MainUtil.SendMail(mail); }
public ActionResult Submit(ContactFormVm vm) { IView pageView = PageContext.Current.PageView; var contactPageItem = Context.Item; if (ModelState.IsValid) { try { //Mail Setting var receiverName = contactPageItem.Fields[FrasersContent.Templates.ContactFormMainSite.Fields.ReceiverName].Value; var receiverEmail = contactPageItem.Fields[FrasersContent.Templates.ContactFormMainSite.Fields.ReceiverEmail].Value; var noReplyEmail = contactPageItem.Fields[FrasersContent.Templates.ContactFormMainSite.Fields.NoReplyEmail].Value; // Mail Template var subject = contactPageItem.Fields[Foundation.Workflow.Templates.EmailTemplate.Fields.Subject].Value; var emailTemplateMessage = WebUtility.HtmlDecode(contactPageItem.Fields[Foundation.Workflow.Templates.EmailTemplate.Fields.Message].Value); var emailMessage = new MailMessage { IsBodyHtml = true, From = new MailAddress(noReplyEmail), Subject = subject, Body = NotifyTemplateBuilder.ReplacePlaceHodler( emailTemplateMessage, new Dictionary <string, string> { { Foundation.Workflow.Constants.EmailToken.Receiver, receiverName }, { $"[{nameof(vm.Name)}]", vm.Name }, { $"[{nameof(vm.Email)}]", vm.Email }, { $"[{nameof(vm.ContactNo)}]", vm.ContactNo }, { $"[{nameof(vm.Message)}]", vm.Message } } ) }; emailMessage.To.Add(receiverEmail); if (vm.UploadFile != null && vm.UploadFile.ContentLength > 0) { var attachment = new Attachment(vm.UploadFile.InputStream, vm.UploadFile.FileName); emailMessage.Attachments.Add(attachment); } if (emailMessage.To.Count > 0) { MainUtil.SendMail(emailMessage); Log.Info($"Sending Mail to: {emailMessage.To}", this); } return(this.RedirectToRoute(MvcSettings.SitecoreRouteName, new { status = Status.Success })); } catch (Exception ex) { ViewData.Add("Status", Status.Error); ModelState.AddModelError(nameof(ContactFormVm), "Some thing go wrong with server"); Log.Error($"Sending Mail Error: {ex.Message}", this); } } return(this.View(pageView, vm)); }
public void Process(Item[] items, Sitecore.Tasks.CommandItem commandItem, ScheduleItem schedule) { CheckboxField active = commandItem.InnerItem.Fields["active"]; if (active.Checked) { //prepare email message string from = commandItem["from"]; string to = commandItem["to"]; string subject = commandItem["subject"]; MailMessage message = new MailMessage(from, to) { Subject = subject, }; //attach reports in excel format MultilistField reportReferences = commandItem.InnerItem.Fields["reports"]; foreach (Item item in reportReferences.GetItems()) { ReportItem reportItem = null; Report report = null; try { reportItem = new ReportItem(item); report = new Report(); foreach (var sItem in reportItem.Scanners) { report.AddScanner(sItem); } foreach (var vItem in reportItem.Viewers) { report.AddViewer(vItem); } foreach (var fItem in reportItem.Filters) { report.AddFilter(fItem); } report.Run(); //attach to mail message string tempPath = new ASR.Export.HtmlExport(report, reportItem).SaveFile("Automated report " + reportItem.Name, "xls"); Attachment newAttachment = new Attachment(tempPath); message.Attachments.Add(newAttachment); } catch (Exception ex) { message.Body += String.Format("An error occured while running '{0}'\n{1}\n\n", reportItem.Name, ex.ToString()); } } MainUtil.SendMail(message); } }
/// <summary> /// Main Execute method responsible for triggering the e-mail submission /// </summary> /// <param name="data"></param> /// <param name="formSubmitContext"></param> /// <returns></returns> protected override bool Execute(SendMailActionData data, FormSubmitContext formSubmitContext) { Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext)); if (data == null || !(data.ReferenceId != Guid.Empty)) { return(false); } var item = Context.Database.GetItem(new ID(data.ReferenceId)); if (item == null) { return(false); } try { var emailTemplate = new EmailTemplate(item); var emailMessage = new MailMessage { // Subject Subject = ReplaceKeywords(emailTemplate.Subject, formSubmitContext), // From From = new MailAddress(ReplaceKeywords(emailTemplate.From, formSubmitContext)) }; // To FillMailAddressCollection(SplitEmails(ReplaceKeywords(emailTemplate.To, formSubmitContext)), emailMessage.To); // CC FillMailAddressCollection(SplitEmails(ReplaceKeywords(emailTemplate.Cc, formSubmitContext)), emailMessage.CC); // BCC FillMailAddressCollection(SplitEmails(ReplaceKeywords(emailTemplate.Bcc, formSubmitContext)), emailMessage.Bcc); // Text if (!string.IsNullOrEmpty(emailTemplate.MessageRichText)) { emailMessage.Body = ReplaceKeywords(emailTemplate.MessageRichText, formSubmitContext); emailMessage.IsBodyHtml = true; } else { emailMessage.Body = ReplaceKeywords(emailTemplate.MessageText, formSubmitContext); emailMessage.IsBodyHtml = false; } MainUtil.SendMail(emailMessage); return(true); } catch (Exception e) { Log.Error($"[SendMail Action] Error sending e-mail based on template {data.ReferenceId}", e, this); formSubmitContext.Abort(); return(false); } }
private void SendDetailsMessage(PublishEndResultBatchArgs args) { MailMessage message = new MailMessage(this.MailFrom, this.MailTo); message.Subject = $"Publishing job {args.JobData.JobId} finished at {DateTime.Now}"; var itemsAffected = args.Batch.Select(b => b.EntityId).Distinct().Count(); message.Body = "Finished publishing job!\n"; message.Body += $"({itemsAffected}) items were published\n"; message.Body += $"Date: {args.JobData.PublishDate}\n"; message.Body += $"Job Id: {args.JobData.JobId}\n"; message.Body += $"Username: {args.JobData.Username}\n"; MainUtil.SendMail(message); }
/// <summary> /// Sends the email. /// </summary> private void SendEmail() { try { var message = new MailMessage(SettingsFixed.SettingsFromMaster.MailFrom, SettingsFixed.SettingsFromMaster.MailTo) { Subject = SettingsFixed.SettingsFromMaster.MailSubject.Replace("[date]", DateUtil.IsoDateToDateTime(Nexus.LicenseApi.Expiration).ToLongDateString()).Replace("[url]", _url), Body = SettingsFixed.SettingsFromMaster.MailContent.Replace("[date]", DateUtil.IsoDateToDateTime(Nexus.LicenseApi.Expiration).ToLongDateString()).Replace("[url]", _url), IsBodyHtml = true }; MainUtil.SendMail(message); } catch (Exception exception) { Log.Error("SitecoreLicenseExpirationAgent failure", exception, this); } }
public void EmailReports(Item[] itemarray, CommandItem commandItem, ScheduleItem scheduleItem) { var item = commandItem.InnerItem; if (item["active"] != "1") { return; } Log("Starting task"); MultilistField mf = item.Fields["reports"]; if (mf == null) { return; } var force = item["sendempty"] == "1"; var filePaths = mf.GetItems().Select(i => runReport(i, force)); var mailMessage = new MailMessage { From = new MailAddress(item["from"]), Subject = item["subject"], }; var senders = item["to"].Split(','); foreach (var sender in senders) { mailMessage.To.Add(sender); } mailMessage.Body = Sitecore.Web.UI.WebControls.FieldRenderer.Render(item, "text"); mailMessage.IsBodyHtml = true; foreach (var path in filePaths.Where(st => !string.IsNullOrEmpty(st))) { mailMessage.Attachments.Add(new Attachment(path)); } Log("attempting to send message"); MainUtil.SendMail(mailMessage); Log("task finished"); }
/// <summary> /// Send the email based to parameters /// </summary> /// <param name="fromAddress"></param> /// <param name="fromName"></param> /// <param name="toAddresses"></param> /// <param name="ccAddresses"></param> /// <param name="bccAddresses"></param> /// <param name="subject"></param> /// <param name="message"></param> /// <param name="isHtml"></param> private void Send(string fromAddress, string fromName, string toAddresses, string ccAddresses, string bccAddresses, string subject, string message, bool isHtml) { var mailMessage = new MailMessage(); mailMessage.From = new MailAddress(fromAddress, fromName); var toAddressList = toAddresses.Split(','); foreach (var addressItem in toAddressList) { if (!string.IsNullOrEmpty(addressItem)) { mailMessage.To.Add(new MailAddress(addressItem)); } } var ccAddressList = ccAddresses.Split(','); foreach (var addressItem in ccAddressList) { if (!string.IsNullOrEmpty(addressItem)) { mailMessage.CC.Add(new MailAddress(addressItem)); } } var bccAddressList = bccAddresses.Split(','); foreach (var addressItem in bccAddressList) { if (!string.IsNullOrEmpty(addressItem)) { mailMessage.Bcc.Add(new MailAddress(addressItem)); } } mailMessage.Subject = subject; mailMessage.IsBodyHtml = isHtml; mailMessage.Body = message; MainUtil.SendMail(mailMessage); }
protected virtual void Run(ClientPipelineArgs args) { if (!args.IsPostBack) { var email = Context.User.Profile.Email; SheerResponse.Input("Enter your email address", email); args.WaitForPostBack(); } else { if (args.HasResult) { var message = new MailMessage(); message.To.Add(args.Result); var tempPath = this.GetFilePath(); message.Attachments.Add(new Attachment(tempPath)); message.Subject = string.Format("ASR Report ({0})", Current.Context.ReportItem.Name); message.From = new MailAddress(Current.Context.Settings.EmailFrom); message.Body = "Attached is your report sent at " + DateTime.Now.ToString("dd/MM/yyyy HH:mm"); MainUtil.SendMail(message); } } }
public override void Process(ServicePipelineArgs args) { var order = this.GetOrderFromArgs(args); if ((order == null) || (order.Total == null)) { return; } try { var body = this.BuildBody(order); var emailMessage = new MailMessage(SendConfirmationFrom, order.Email, SendConfirmationSubject, body) { IsBodyHtml = true }; MainUtil.SendMail(emailMessage); } catch (Exception ex) { Log.Error("Send order confirmation email failed!", ex, this); } }
public void SendMessage(MailMessage mailMessage) { MainUtil.SendMail(mailMessage); }
/// <summary> /// Sends the specified message. /// </summary> /// <param name="message">The message.</param> public override void Send([NotNull] MailMessage message) { Assert.ArgumentNotNull(message, "message"); MainUtil.SendMail(message); }
public void EmailReports(Item[] itemarray, CommandItem commandItem, ScheduleItem scheduleItem) { var item = commandItem.InnerItem; if (item["active"] != "1") { return; } Log("Starting report email task"); MultilistField mf = item.Fields["reports"]; if (mf == null) { return; } var force = item["sendempty"] == "1"; var isHtmlExportType = item["Export Type"].ToLower() == "html"; var filePaths = mf.GetItems().Select(i => runReport(i, force, isHtmlExportType)); MailMessage mailMessage; try { mailMessage = new MailMessage { From = new MailAddress(item["from"]), Subject = setDate(item["subject"]), }; } catch (Exception) { LogException("FROM email address error." + item["from"]); return; } var senders = item["to"].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var sender in senders) { // test that each email address is valid. Continue to the next if it isn't. try { var toAddress = new MailAddress(sender); mailMessage.To.Add(toAddress); } catch (Exception) { LogException("TO email address error. " + sender); } } string[] ccAddressList = item["cc"].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (ccAddressList.Any()) { foreach (var ccAddress in ccAddressList) { try { // test that each email address is valid. Continue to the next if it isn't. MailAddress ccMailAddress = new MailAddress(ccAddress); mailMessage.CC.Add(ccMailAddress); } catch (Exception) { LogException("CC email address error. " + ccAddress); } } } string[] bccAddressList = item["bcc"].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (bccAddressList.Any()) { foreach (var bccAddress in bccAddressList) { try { // test that each email address is valid. Continue to the next if it isn't. MailAddress bccMailAddress = new MailAddress(bccAddress); mailMessage.Bcc.Add(bccMailAddress); } catch (Exception) { LogException("BCC email address error. " + bccAddress); } } } mailMessage.Body = setDate(Sitecore.Web.UI.WebControls.FieldRenderer.Render(item, "text")); mailMessage.IsBodyHtml = true; foreach (var path in filePaths.Where(st => !string.IsNullOrEmpty(st))) { mailMessage.Attachments.Add(new Attachment(path)); } Log("attempting to send message"); MainUtil.SendMail(mailMessage); Log("task report email finished"); }
public void EmailReports(Item[] itemarray, CommandItem commandItem, ScheduleItem scheduleItem) { var item = commandItem.InnerItem; if (item["active"] != "1") { return; } Log("Starting report email task"); MultilistField mf = item.Fields["reports"]; if (mf == null) { return; } var force = item["sendempty"] == "1"; var filePaths = mf.GetItems().Select(i => runReport(i, force)); MailMessage mailMessage; try { mailMessage = new MailMessage { From = new MailAddress(item["from"]), Subject = item["subject"], }; } catch (Exception ex) { LogException("FROM email address error."); return; } var senders = item["to"].Split(','); foreach (var sender in senders) { // test that each email address is valid. Continue to the next if it isn't. try { var toAddress = new MailAddress(sender); mailMessage.To.Add(toAddress); } catch (Exception) { LogException("TO email address error. " + sender); } } mailMessage.Body = Sitecore.Web.UI.WebControls.FieldRenderer.Render(item, "text"); mailMessage.IsBodyHtml = true; foreach (var path in filePaths.Where(st => !string.IsNullOrEmpty(st))) { mailMessage.Attachments.Add(new Attachment(path)); } Log("attempting to send message"); MainUtil.SendMail(mailMessage); Log("task report email finished"); }