private void cmdSubscribe_Click(object sender, System.EventArgs e) { string emailAddress = txtEmail.Text; if (emailAddress == null || emailAddress == string.Empty) { AddErrorMessage(Translate("/bvnetwork/sendmail/subscribe/errornoemail")); return; } emailAddress = emailAddress.Trim(); EPiMailEngine engine = new EPiMailEngine(); ArrayList resultArray = new ArrayList(); EmailAddresses importedItems = new EmailAddresses(); foreach (ListItem itm in this.chkNewsLetterLists.Items) { if (itm.Selected) { // Check that the user does not belong to the groups // already. RecipientList list = RecipientList.Load(Convert.ToInt32(itm.Value)); SubscriptionStatus status = new SubscriptionStatus(); status.RecipientListName = list.Name; //Load and check if the email typed by the user exists. EmailAddress emailItem = EmailAddress.Load(list.Id, emailAddress); if (emailItem == null) { // Create it, and save it. It is automatically // added to the WorkItems collection emailItem = list.CreateEmailAddress(emailAddress); // Save emailItem.Save(); status.SubscriptionResult = true; } else { // Already subscribes status.SubscriptionResult = true; status.Message = Translate("/bvnetwork/sendmail/subscribe/alreadysubscribe"); } resultArray.Add(status); } } // Done adding, now show the result rptResult.DataSource = resultArray; rptResult.DataBind(); }
private void Page_Load(object sender, System.EventArgs e) { // We cannot use "id" as the friendly url rewriter will // remove it for us int id = int.Parse(this.Request["pageid"]); PageReference pageRef = new PageReference(id); // Get content to send string html = new EPiMailEngine().GetPreviewHtml(pageRef); Response.Write(html); }
/// <summary> /// Verifies the environment. This should be done /// before sending the email. /// </summary> /// <returns>True means ok to send, false means something is wrong</returns> public bool VerifyEnvironment(EPiMailEngine engine) { Library.EnvironmentVerification envVer = engine.VerifyEnvironment(); if (envVer.HasErrors() || envVer.HasWarnings()) { ucEnvironmentVerification.VerificationItems = envVer.VerificationItems; ucEnvironmentVerification.Visible = true; // Stop here if errors if (envVer.HasErrors()) { return(false); } } return(true); }
private void cmdUnsubscribe_Click(object sender, System.EventArgs e) { string emailAddress = txtEmail.Text; if (emailAddress == null || emailAddress == string.Empty) { AddErrorMessage(Translate("/bvnetwork/sendmail/unsubscribe/errornoemail")); return; } emailAddress = emailAddress.Trim(); EPiMailEngine engine = new EPiMailEngine(); ArrayList resultArray = new ArrayList(); EmailAddresses importedItems = new EmailAddresses(); foreach (ListItem itm in this.chkNewsLetterLists.Items) { if (itm.Selected) { //Load the selected recipient list RecipientList list = RecipientList.Load(Convert.ToInt32(itm.Value)); SubscriptionStatus status = new SubscriptionStatus(); status.RecipientListName = list.Name; //load user email address EmailAddress emailItem = EmailAddress.Load(list.Id, emailAddress); if (emailItem != null) { //Delete the user from the list, and show a confirm message emailItem.Delete(); status.SubscriptionResult = true; status.Message = Translate("/bvnetwork/sendmail/unsubscribe/recipientremoved"); } else { status.SubscriptionResult = false; status.Message = Translate("/bvnetwork/sendmail/unsubscribe/nosubscriptionfound"); } //add the result to the array list. resultArray.Add(status); } } // Done adding, now show the result rptResult.DataSource = resultArray; rptResult.DataBind(); }
/// <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); } }
/// <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()); } }
protected EPiMailEngine GetEmailEngine() { EPiMailEngine engine = new EPiMailEngine(); return(engine); }