/// <summary> /// Verifies the environment, called before the send process /// starts to verify that important settings and infrastructure /// is in place. /// </summary> /// <returns>An EnvironmentVerification object, holding all the verification tests that has been run</returns> public virtual EnvironmentVerification VerifyEnvironment() { EnvironmentVerification env = new EnvironmentVerification(); // Verify all the settings // Get the registered filter for working with recipients RecipientsUtility recipUtil = new RecipientsUtility(); SmtpClient client = EPiMailEngine.GetConfiguredSmtpClient(); // Need an smtp server specified if (string.IsNullOrEmpty(client.Host) == true) { env.VerificationItems.Add(VerificationType.Error, "Missing Smtp host setting in web.config. The aspnetEmail component requires a SMTP server to be specified."); } // Verify license file if (DoesLicenseFileExist() == false) { env.VerificationItems.Add(VerificationType.Error, "Can't find aspNetEmail License file: " + GetLocalLicenseFilePath()); } return(env); }
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> /// 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> /// Verifies the environment, called before the send process /// starts to verify that important settings and infrastructure /// is in place. /// </summary> /// <returns>An EnvironmentVerification object, holding all the verification tests that has been run</returns> public virtual EnvironmentVerification VerifyEnvironment() { EnvironmentVerification env = new EnvironmentVerification(); SmtpClient client = EPiMailEngine.GetConfiguredSmtpClient(); // Need an smtp server specified if (string.IsNullOrEmpty(client.Host) && string.IsNullOrEmpty(client.PickupDirectoryLocation)) { env.VerificationItems.Add(VerificationType.Error, "Missing Smtp settings in web.config. You need to configure smtp network host or a pickup directory."); } return(env); }
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> /// Does the actual send action for the emails, using the System.Web.Mail namespace /// </summary> /// <param name="mail"></param> /// <param name="onlyTestDontSendMail"></param> /// <returns></returns> internal bool SendMail(MailMessage mail, bool onlyTestDontSendMail) { //don't send mail if localhost is set to smtp-server (probably in development enviroment) // 20051219 SC: Comment above is sound, but there is no test for it if (!onlyTestDontSendMail) { // mail. .UrlContentBase = SiteDefinition.Current.SiteUrl.ToString(); mail.BodyEncoding = System.Text.Encoding.UTF8; SmtpClient client = EPiMailEngine.GetConfiguredSmtpClient(); client.Send(mail); return(true); } return(false); }
/// <summary> /// Initializes the mail settings. /// </summary> /// <param name="mail">The mail.</param> protected void InitializeMailSettings(ref EmailMessage mail) { SmtpClient client = EPiMailEngine.GetConfiguredSmtpClient(); // Server mail.Server = client.Host; // Port mail.Port = client.Port; //// User/password may both be empty -- in that case just ignore everything... //if (string.IsNullOrEmpty(userName) == false || // string.IsNullOrEmpty(password) == false) //{ // // If one has been defined, the other must also be defined // if (string.IsNullOrEmpty(userName)) // throw new EPiServerException("Undefined username"); // if (string.IsNullOrEmpty(password)) // throw new EPiServerException("Undefined password"); // mail.Username = userName; // mail.Password = password; // } }
protected EPiMailEngine GetEmailEngine() { EPiMailEngine engine = new EPiMailEngine(); return engine; }
/// <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; }