public void BindWorkItemData(JobWorkItems items) { grdWorkItems.DataSource = items; grdWorkItems.DataBind(); lblGridCount.Text = items.Items.Count.ToString(); pnlGridCount.Visible = true; }
protected void cmdSearchFor_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtSearchFor.Text.Trim())) { return; } JobWorkItems items = JobWorkItems.Search(NewsletterJob.Id, "%" + txtSearchFor.Text + "%"); BindWorkItemData(items); }
/// <summary> /// Sends the mail. /// </summary> /// <param name="engine">The engine.</param> /// <param name="workItems">The work items.</param> public void SendMail(EPiMailEngine engine, JobWorkItems workItems, bool isTestSend) { if (_log.IsDebugEnabled()) _log.Debug("Starting send process. Testmode: " + isTestSend.ToString()); // First we verify the environment if (VerifyEnvironment(engine) == false) return; // Collection of recipients from job if (workItems == null) throw new NullReferenceException("workItems cannot be null when sending newsletter"); if (workItems.Items.Count == 0) { ShowError("No recipients defined. Please add email addresses to textbox above Test Send button."); return; } // Need default values // 1. Use MailSender property // 2. Use EPsSendMailFromAddress from web.config // 3. Construct newsletter@<sitename> string fromAddress = MailFrom; // 1. Use MailSubject property // 2. Use EPsSendMailSubject from web.config // 3. Use "Newsletter" as default string subject = MailSubject; if (isTestSend) subject += TEST_SUBJECT_POSTFIX; if (_log.IsDebugEnabled()) _log.Debug(string.Format("Start sending newsletter based on WorkItems. Subject: '{0}', From: '{1}', Count '{2}', Test Mode: '{3}'", subject, fromAddress, workItems.Items.Count.ToString(), isTestSend.ToString())); // Send the message string sendStatus; // We set testsend as false in the method below, as the test sending UI has changed, but the // logic in the engine interpret this as not sending anything. Test here means change the // email subject SendMailLog log = engine.SendNewsletter(subject, fromAddress, CurrentPage.ContentLink , workItems, false); sendStatus = log.GetClearTextLogString(true); lblSendResult.Text = sendStatus; pnlSendResult.Visible = true; if (_log.IsDebugEnabled()) _log.Debug("Send process finished. Testmode: " + isTestSend.ToString()); }
/// <summary> /// Sends the newsletter. /// </summary> /// <returns></returns> private string SendNewsletter(Job job) { JobWorkItems workItemsForProcessing = job.GetWorkItems(); if (workItemsForProcessing.Items.Count == 0) { DebugWrite("Work Items collection is empty. Nothing to send."); return("Work Items collection is empty. Nothing to send."); } // Get information about what we're about to send EPiMailEngine mailEngine = new EPiMailEngine(); MailSenderBase msbase = mailEngine.GetMailSender(); MailInformation mailInfo = msbase.GetMailMetaData(new PageReference(job.PageId)); // const int sleepTestInterval = 0; DebugWrite(string.Format("Start sending newsletter. Job name: '{0}', Subject: '{1}', From: '{2}'", job.Name, mailInfo.Subject, mailInfo.From)); // Send the message // For testing, it can be nice to control the time it takes to send // each batch //#if DEBUG // if (sleepTestInterval > 0) // System.Threading.Thread.Sleep(sleepTestInterval); //#endif // Send with status SendMailLog log; log = mailEngine.SendNewsletter(mailInfo.Subject, mailInfo.From, /* Who we send from */ mailInfo.PageLink, /* The page to send */ workItemsForProcessing, /* Who we send to */ false /* Not Test Mode */); //#if DEBUG // if (sleepTestInterval > 0) // System.Threading.Thread.Sleep(sleepTestInterval); //#endif return(log.GetClearTextLogString(true /* Use br instead of \n */)); }
void SendTest_ClickHandler(object sender, EventArgs e) { string sendTo = txtSendTestTo.Text.Trim(); if (string.IsNullOrEmpty(sendTo)) { ShowError("Please add one or more email addresses to send the test to."); } else { /// TODO: Store personalization data from the user profile instad // Save email addresses for next time // PersonalizedData.Current["EPiSendMailSavedTestAddresses"] = sendTo; // Parse items, set ready for sending JobWorkItems items = Job.ParseEmailAddressesToWorkItems(sendTo, JobWorkStatus.Sending); EPiMailEngine engine = GetEmailEngine(); SendMail(engine, items, true); } }
protected void cmdRemoveCsvEmailAddresses_Click(object sender, EventArgs e) { string addresses = txtRemoveEmailWorkItems.Text; if (string.IsNullOrEmpty(addresses)) { _feedbackCtrl.ShowError("Please enter email addresses to remove."); return; } JobWorkItems itemsToAttemptDelete = Job.ParseEmailAddressesToWorkItems(addresses); foreach (JobWorkItem item in itemsToAttemptDelete) { item.JobId = _job.Id; item.Delete(); } _feedbackCtrl.ShowInfo("Removed email addresses"); }
/// <summary> /// Send mail to mailreceivers using Mailgun REST API /// </summary> /// <param name="mailInfo"></param> /// <param name="recepients">receivers</param> /// <param name="testMode">No mails are sent, generating report for user</param> /// <returns>A html formatted report of the send process</returns> public override SendMailLog SendEmail(MailInformation mailInfo, JobWorkItems recepients, bool testMode) { _log.Debug("Starting Mailgun Send"); // Inline all css InlineResult cssInline = PreMailer.Net.PreMailer.MoveCssInline(mailInfo.BodyHtml); mailInfo.BodyHtml = cssInline.Html; // Base will send SendMailLog log = base.SendEmail(mailInfo, recepients, testMode); // Log any messages, debug is only detected // if we have an HttpContext. if (IsInDebugMode()) { log.WarningMessages.Add("Premailer CSS warning messages are only shown in debug mode. Primarily for developers."); log.WarningMessages.AddRange(cssInline.Warnings.ToArray()); } _log.Debug("Ending Mailgun Send"); // return report return(log); }
/// <summary> /// Send mail to mailreceivers using System.Web.Mail /// </summary> /// <param name="mailInfo"></param> /// <param name="recipients"></param> /// <param name="testMode">No mails are sent, generating report for user</param> /// <returns>A SendMailLog object with information about the status of the job.</returns> public override SendMailLog SendEmail(MailInformation mailInfo, JobWorkItems recipients, bool testMode) { _log.Debug("900.10.11.1 Starting Send"); // for logging SendMailLog log = new SendMailLog(); log.StartJob(); // Recipients util RecipientsUtility recipUtil = new RecipientsUtility(); // We try to verify as many settings, variables etc. before // starting the sending loop, as we don't want to generate // lots of exceptions in a loop. // Need someone to send to if (recipients.Items.Count == 0) { _log.Error("900.10.11.2 Trying to send mail with an empty JobWorkItems collection. Please check the collection before attemting to send mail."); throw new ArgumentNullException("Recipient collection is empty, there is no recipients to send to.", "recepients"); } // And, we need a sender address if (mailInfo.From == null || mailInfo.From == string.Empty) { _log.Error("900.10.11.3 Missing from address. SMTP servers do not allow sending without a sender."); throw new ArgumentNullException("Missing from address. SMTP servers do not allow sending without a sender.", "mailInfo.From"); } // Load the license. This needs to be in the EmailMessage.LoadLicenseString(GetLicenseFileContents()); // We'll reuse the mail object, so we create it outside of the loop EmailMessage mail = CreateMessage(mailInfo); // Set port and authentication details if found InitializeMailSettings(ref mail); // Send a warm-up message outside the loop. This // will help us catch any misconfigurations and other // things that prevents us from sending emails. By // doing this outside the loop, we won't kill the // application or log with uneccesary error messages. // TODO: Implement this // Loop through receivers collection, send email for each foreach (JobWorkItem workItem in recipients) { _log.Debug(string.Format("900.10.11.5 Job {0}, Email: {1}, Status: {2}", workItem.JobId.ToString(), workItem.EmailAddress, workItem.Status.ToString())); // Only attempt sending those that have been stamped as ready for sending // unless we're in a test case. if (workItem.Status == JobWorkStatus.Sending || testMode == true) { try { // At this point we assume the address is formatted correctly // and checked, but aspNetEmail checks the to address on set, may fail mail.To = workItem.EmailAddress; // Perform actual send, if testmail, then this will // return false. We should not update the status on // test sends bool result = SendMail(mail, testMode); if (result == true) { log.SuccessMessages.Add(workItem.EmailAddress); // Update status and save it // TODO: Improve performance by doing this in batch workItem.Status = JobWorkStatus.Complete; // Only save if real work item (could be a test item) if (workItem.JobId > 0) { workItem.Save(); } } // else // Could not send, it has been disabled by // settings or parameters } catch (Exception ex) { _log.Error(string.Format("900.10.11.6 Error sending to email: {0}", workItem.EmailAddress), ex); string exceptionMsg = string.Format("Email: {0}\r\nException: {1}\r\n\r\n", workItem.EmailAddress, ex.Message); log.ErrorMessages.Add(exceptionMsg); // Update work item workItem.Status = JobWorkStatus.Failed; if (exceptionMsg.Length >= 2000) { exceptionMsg = exceptionMsg.Substring(0, 1999); } workItem.Info = exceptionMsg; if (workItem.JobId > 0) { workItem.Save(); } } } else { _log.Debug(string.Format("900.10.11.7 Skipping Recipient, wrong status. Job {0}, Email: {1}, Status: {2}", workItem.JobId.ToString(), workItem.EmailAddress, workItem.Status.ToString())); } } // Finished log.StopJob(); // Warn user if logging is enabled if (Configuration.NewsLetterConfiguration.ExtendedLogFile != null) { log.WarningMessages.Add("Logging has been enabled. Only use during troubleshooting."); } _log.Debug("900.10.11.8 Ending Send"); // return report return(log); }
/// <summary> /// /// </summary> /// <param name="mailInfo"></param> /// <param name="recepients">receivers</param> /// <param name="testMode">No mails are sent, generating report for user</param> /// <returns>A html formatted report of the send process</returns> public override SendMailLog SendEmail(MailInformation mailInfo, JobWorkItems recepients, bool testMode) { _log.Debug("Starting Send"); // for logging SendMailLog log = new SendMailLog(); // Need someone to send to if (recepients.Items.Count == 0) { _log.Error("Trying to send newsletter with an empty JobWorkCollection. Please check the collection before attemting to send mail."); throw new ArgumentNullException("recepients", "Recipient collection is empty, there is no recipients to send to."); } // And, we need a sender address if (string.IsNullOrEmpty(mailInfo.From)) { _log.Error("Missing from address."); throw new ArgumentNullException("mailInfo", "Missing from address."); } // Inline all css PreMailer.Net.PreMailer preMailer = new PreMailer.Net.PreMailer(mailInfo.BodyHtml); if (mailInfo.Utm.HasValidUtmCode) { preMailer.AddAnalyticsTags(mailInfo.Utm.Source, mailInfo.Utm.Medium, mailInfo.Utm.Campaign, mailInfo.Utm.Content); } InlineResult cssInline = preMailer.MoveCssInline(); mailInfo.BodyHtml = cssInline.Html; // Log any messages, debug is only detected // if we have an HttpContext. if (IsInDebugMode()) { log.WarningMessages.Add("Premailer CSS warning messages are only shown in debug mode. Primarily for developers."); log.WarningMessages.AddRange(cssInline.Warnings.ToArray()); } // Loop through receivers collection, add to collection and send // one email per batch size. int batchRun = 0; int batchSize = GetBatchSize(); do { IEnumerable<JobWorkItem> workItems = recepients.Skip(batchRun*batchSize).Take(batchSize); int numberofItemsToSend = workItems.Count(); if (numberofItemsToSend == 0) break; batchRun++; try { if (SendMailBatch(mailInfo, workItems, testMode)) { // Mark each item as sent foreach (JobWorkItem workItem in workItems) { log.SuccessMessages.Add(workItem.EmailAddress); // Update status and save it workItem.Status = JobWorkStatus.Complete; // Only save if real work item (could be a test item) if (workItem.JobId > 0) workItem.Save(); } } } catch (Exception ex) { _log.Error(string.Format("Error sending batch (to {0} recipients).", recepients.Count()), ex); string exceptionMsg = ex.Message; log.ErrorMessages.Add(exceptionMsg); // Update work item foreach (JobWorkItem workItem in workItems) { workItem.Status = JobWorkStatus.Failed; if (exceptionMsg.Length >= 2000) exceptionMsg = exceptionMsg.Substring(0, 1999); workItem.Info = exceptionMsg; if (workItem.JobId > 0) workItem.Save(); } // can't continue break; } } while (true); // Finished log.SendStop = DateTime.Now; _log.Debug("Ending Send"); // return report return log; }
/// <summary> /// Handles the Click event of the lnkShowError control. Shows all work items /// with the status of error /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void lnkShowError_Click(object sender, EventArgs e) { JobWorkItems items = JobWorkItems.ListAll(NewsletterJob, JobWorkStatus.Failed); BindWorkItemData(items); }
/// <summary> /// Send mail to mailreceivers using System.Web.Mail /// </summary> /// <param name="mailInfo"></param> /// <param name="recipients"></param> /// <param name="testMode">No mails are sent, generating report for user</param> /// <returns>A SendMailLog object with information about the status of the job.</returns> public override SendMailLog SendEmail(MailInformation mailInfo, JobWorkItems recipients, bool testMode) { _log.Debug("900.10.11.1 Starting Send"); // for logging SendMailLog log = new SendMailLog(); log.StartJob(); // Recipients util RecipientsUtility recipUtil = new RecipientsUtility(); // We try to verify as many settings, variables etc. before // starting the sending loop, as we don't want to generate // lots of exceptions in a loop. // Need someone to send to if (recipients.Items.Count == 0) { _log.Error("900.10.11.2 Trying to send mail with an empty JobWorkItems collection. Please check the collection before attemting to send mail."); throw new ArgumentNullException("Recipient collection is empty, there is no recipients to send to.", "recepients"); } // And, we need a sender address if (mailInfo.From == null || mailInfo.From == string.Empty) { _log.Error("900.10.11.3 Missing from address. SMTP servers do not allow sending without a sender."); throw new ArgumentNullException("Missing from address. SMTP servers do not allow sending without a sender.", "mailInfo.From"); } // Load the license. This needs to be in the EmailMessage.LoadLicenseString(GetLicenseFileContents()); // We'll reuse the mail object, so we create it outside of the loop EmailMessage mail = CreateMessage(mailInfo); // Set port and authentication details if found InitializeMailSettings(ref mail); // Send a warm-up message outside the loop. This // will help us catch any misconfigurations and other // things that prevents us from sending emails. By // doing this outside the loop, we won't kill the // application or log with uneccesary error messages. // TODO: Implement this // Loop through receivers collection, send email for each foreach (JobWorkItem workItem in recipients) { _log.Debug(string.Format("900.10.11.5 Job {0}, Email: {1}, Status: {2}", workItem.JobId.ToString(), workItem.EmailAddress, workItem.Status.ToString())); // Only attempt sending those that have been stamped as ready for sending // unless we're in a test case. if (workItem.Status == JobWorkStatus.Sending || testMode == true) { try { // At this point we assume the address is formatted correctly // and checked, but aspNetEmail checks the to address on set, may fail mail.To = workItem.EmailAddress; // Perform actual send, if testmail, then this will // return false. We should not update the status on // test sends bool result = SendMail(mail, testMode); if (result == true) { log.SuccessMessages.Add(workItem.EmailAddress); // Update status and save it // TODO: Improve performance by doing this in batch workItem.Status = JobWorkStatus.Complete; // Only save if real work item (could be a test item) if (workItem.JobId > 0) workItem.Save(); } // else // Could not send, it has been disabled by // settings or parameters } catch (Exception ex) { _log.Error(string.Format("900.10.11.6 Error sending to email: {0}", workItem.EmailAddress), ex); string exceptionMsg = string.Format("Email: {0}\r\nException: {1}\r\n\r\n", workItem.EmailAddress, ex.Message); log.ErrorMessages.Add(exceptionMsg); // Update work item workItem.Status = JobWorkStatus.Failed; if (exceptionMsg.Length >= 2000) exceptionMsg = exceptionMsg.Substring(0, 1999); workItem.Info = exceptionMsg; if (workItem.JobId > 0) workItem.Save(); } } else { _log.Debug(string.Format("900.10.11.7 Skipping Recipient, wrong status. Job {0}, Email: {1}, Status: {2}", workItem.JobId.ToString(), workItem.EmailAddress, workItem.Status.ToString())); } } // Finished log.StopJob(); // Warn user if logging is enabled if (Configuration.NewsLetterConfiguration.ExtendedLogFile != null) log.WarningMessages.Add("Logging has been enabled. Only use during troubleshooting."); _log.Debug("900.10.11.8 Ending Send"); // return report return log; }
protected void lnkShowSent_Click(object sender, EventArgs e) { JobWorkItems items = JobWorkItems.ListAll(NewsletterJob, JobWorkStatus.Complete); BindWorkItemData(items); }
/// <summary> /// Send mail to mailreceivers /// </summary> /// <param name="subject">subject for mail</param> /// <param name="pageRef">reference to mailpage</param> /// <param name="from">from-address for mail</param> /// <param name="onlyTestDontSendMail">No mails are sent, generating report for user</param> /// <param name="job">The job to send as newsletter</param> /// <returns></returns> public SendMailLog SendNewsletter(string subject, string from, ContentReference pageRef, JobWorkItems workItems, bool onlyTestDontSendMail) { // Construct correct sender object based on config setting MailSenderBase sender = GetMailSender(); // Construct mail object with default values and content MailInformation mailInfo = GetMailInformation(sender, pageRef, from, subject); // Send it SendMailLog log; log = sender.SendEmail(mailInfo, workItems, onlyTestDontSendMail); // Add additional information to the log log.Subject = subject; return log; }
/// <summary> /// Send mail to mailreceivers using System.Net.Mail /// </summary> /// <param name="mailInfo"></param> /// <param name="recepients">receivers</param> /// <param name="from">from-address for mail</param> /// <param name="testMode">No mails are sent, generating report for user</param> /// <returns>A html formatted report of the send process</returns> public override SendMailLog SendEmail(MailInformation mailInfo, JobWorkItems recepients, bool testMode) { _log.Debug("Starting Send"); // for logging SendMailLog log = new SendMailLog(); log.SendStart = DateTime.Now; // HttpContext.Current.Server.ScriptTimeout = 7200; // Need someone to send to if (recepients.Items.Count == 0) { _log.Error("Trying to send newsletter with an empty JobWorkCollection. Please check the collection before attemting to send mail."); throw new ArgumentNullException("recepients", "Recipient collection is empty, there is no recipients to send to."); } // And, we need a sender address if (string.IsNullOrEmpty(mailInfo.From)) { _log.Error("Missing from address. SMTP servers do not allow sending without a sender."); throw new ArgumentNullException("mailInfo", "Missing from address. SMTP servers do not allow sending without a sender."); } // Loop through receivers collection, send email for each foreach (JobWorkItem recipient in recepients) { _log.Debug(string.Format("Job {0}, Email: {1}, Status: {2}", recipient.JobId.ToString(), recipient.EmailAddress, recipient.Status.ToString())); MailMessage mail = new MailMessage(mailInfo.From, recipient.EmailAddress); mail.Subject = mailInfo.Subject; mail.Body = mailInfo.BodyHtml; mail.IsBodyHtml = true; try { if (SendMail(mail, testMode)) { log.SuccessMessages.Add(recipient.EmailAddress); // Update status and save it recipient.Status = JobWorkStatus.Complete; // Only save if real work item (could be a test item) if (recipient.JobId > 0) { recipient.Save(); } } } catch (Exception ex) { _log.Error(string.Format("Error sending to email: {0}", recipient.EmailAddress), ex); string exceptionMsg = string.Format("Email: {0}\r\nException: {1}\r\n\r\n", recipient.EmailAddress, ex.Message); log.ErrorMessages.Add(exceptionMsg); // Update work item recipient.Status = JobWorkStatus.Failed; if (exceptionMsg.Length >= 2000) { exceptionMsg = exceptionMsg.Substring(0, 1999); } recipient.Info = exceptionMsg; if (recipient.JobId > 0) { recipient.Save(); } } } // Finished log.SendStop = DateTime.Now; _log.Debug("Ending Send"); // return report return(log); }
/// <summary> /// Send mail to mailreceivers using System.Web.Mail /// </summary> /// <param name="mailInfo">A MailInformation object with the content to send</param> /// <param name="recepients">receivers</param> /// <param name="testMode">No mails are sent, generating report for user</param> /// <returns>A report of the send process</returns> public abstract SendMailLog SendEmail(MailInformation mailInfo, JobWorkItems recepients, bool testMode);
/// <summary> /// /// </summary> /// <param name="mailInfo"></param> /// <param name="recepients">receivers</param> /// <param name="testMode">No mails are sent, generating report for user</param> /// <returns>A html formatted report of the send process</returns> public override SendMailLog SendEmail(MailInformation mailInfo, JobWorkItems recepients, bool testMode) { _log.Debug("Starting Send"); // for logging SendMailLog log = new SendMailLog(); // Need someone to send to if (recepients.Items.Count == 0) { _log.Error("Trying to send newsletter with an empty JobWorkCollection. Please check the collection before attemting to send mail."); throw new ArgumentNullException("recepients", "Recipient collection is empty, there is no recipients to send to."); } // And, we need a sender address if (string.IsNullOrEmpty(mailInfo.From)) { _log.Error("Missing from address."); throw new ArgumentNullException("mailInfo", "Missing from address."); } // Inline all css PreMailer.Net.PreMailer preMailer = new PreMailer.Net.PreMailer(mailInfo.BodyHtml); if (mailInfo.Utm.HasValidUtmCode) { preMailer.AddAnalyticsTags(mailInfo.Utm.Source, mailInfo.Utm.Medium, mailInfo.Utm.Campaign, mailInfo.Utm.Content); } InlineResult cssInline = preMailer.MoveCssInline(); mailInfo.BodyHtml = cssInline.Html; // Log any messages, debug is only detected // if we have an HttpContext. if (IsInDebugMode()) { log.WarningMessages.Add("Premailer CSS warning messages are only shown in debug mode. Primarily for developers."); log.WarningMessages.AddRange(cssInline.Warnings.ToArray()); } // Loop through receivers collection, add to collection and send // one email per batch size. int batchRun = 0; int batchSize = GetBatchSize(); do { IEnumerable <JobWorkItem> workItems = recepients.Skip(batchRun * batchSize).Take(batchSize); int numberofItemsToSend = workItems.Count(); if (numberofItemsToSend == 0) { break; } batchRun++; try { if (SendMailBatch(mailInfo, workItems, testMode)) { // Mark each item as sent foreach (JobWorkItem workItem in workItems) { log.SuccessMessages.Add(workItem.EmailAddress); // Update status and save it workItem.Status = JobWorkStatus.Complete; // Only save if real work item (could be a test item) if (workItem.JobId > 0) { workItem.Save(); } } } } catch (Exception ex) { _log.Error(string.Format("Error sending batch (to {0} recipients).", recepients.Count()), ex); string exceptionMsg = ex.Message; log.ErrorMessages.Add(exceptionMsg); // Update work item foreach (JobWorkItem workItem in workItems) { workItem.Status = JobWorkStatus.Failed; if (exceptionMsg.Length >= 2000) { exceptionMsg = exceptionMsg.Substring(0, 1999); } workItem.Info = exceptionMsg; if (workItem.JobId > 0) { workItem.Save(); } } // can't continue break; } } while (true); // Finished log.SendStop = DateTime.Now; _log.Debug("Ending Send"); // return report return(log); }
/// <summary> /// Sends the mail. /// </summary> /// <param name="engine">The engine.</param> /// <param name="workItems">The work items.</param> public void SendMail(EPiMailEngine engine, JobWorkItems workItems, bool isTestSend) { if (_log.IsDebugEnabled()) { _log.Debug("Starting send process. Testmode: " + isTestSend.ToString()); } // First we verify the environment if (VerifyEnvironment(engine) == false) { return; } // Collection of recipients from job if (workItems == null) { throw new NullReferenceException("workItems cannot be null when sending newsletter"); } if (workItems.Items.Count == 0) { ShowError("No recipients defined. Please add email addresses to textbox above Test Send button."); return; } // Need default values // 1. Use MailSender property // 2. Use EPsSendMailFromAddress from web.config // 3. Construct newsletter@<sitename> string fromAddress = MailFrom; // 1. Use MailSubject property // 2. Use EPsSendMailSubject from web.config // 3. Use "Newsletter" as default string subject = MailSubject; if (isTestSend) { subject += TEST_SUBJECT_POSTFIX; } if (_log.IsDebugEnabled()) { _log.Debug(string.Format("Start sending newsletter based on WorkItems. Subject: '{0}', From: '{1}', Count '{2}', Test Mode: '{3}'", subject, fromAddress, workItems.Items.Count.ToString(), isTestSend.ToString())); } // Send the message string sendStatus; // We set testsend as false in the method below, as the test sending UI has changed, but the // logic in the engine interpret this as not sending anything. Test here means change the // email subject SendMailLog log = engine.SendNewsletter(subject, fromAddress, CurrentPage.ContentLink, workItems, false); sendStatus = log.GetClearTextLogString(true); lblSendResult.Text = sendStatus; pnlSendResult.Visible = true; if (_log.IsDebugEnabled()) { _log.Debug("Send process finished. Testmode: " + isTestSend.ToString()); } }
/// <summary> /// Send mail to mailreceivers /// </summary> /// <param name="subject">subject for mail</param> /// <param name="pageRef">reference to mailpage</param> /// <param name="from">from-address for mail</param> /// <param name="onlyTestDontSendMail">No mails are sent, generating report for user</param> /// <param name="job">The job to send as newsletter</param> /// <returns></returns> public SendMailLog SendNewsletter(string subject, string from, ContentReference pageRef, JobWorkItems workItems, bool onlyTestDontSendMail) { // Construct correct sender object based on config setting MailSenderBase sender = GetMailSender(); // Construct mail object with default values and content MailInformation mailInfo = GetMailInformation(sender, pageRef, from, subject); // Send it SendMailLog log; log = sender.SendEmail(mailInfo, workItems, onlyTestDontSendMail); // Add additional information to the log log.Subject = subject; return(log); }
/// <summary> /// Send mail to mailreceivers using Mailgun REST API /// </summary> /// <param name="mailInfo"></param> /// <param name="recepients">receivers</param> /// <param name="testMode">No mails are sent, generating report for user</param> /// <returns>A html formatted report of the send process</returns> public override SendMailLog SendEmail(MailInformation mailInfo, JobWorkItems recepients, bool testMode) { _log.Debug("Starting Mailgun Send"); // Inline all css InlineResult cssInline = PreMailer.Net.PreMailer.MoveCssInline(mailInfo.BodyHtml); mailInfo.BodyHtml = cssInline.Html; // Base will send SendMailLog log = base.SendEmail(mailInfo, recepients, testMode); // Log any messages, debug is only detected // if we have an HttpContext. if (IsInDebugMode()) { log.WarningMessages.Add("Premailer CSS warning messages are only shown in debug mode. Primarily for developers."); log.WarningMessages.AddRange(cssInline.Warnings.ToArray()); } _log.Debug("Ending Mailgun Send"); // return report return log; }