/// <summary> /// Send email with recovery password link. /// </summary> /// <param name="userConnection">User connection.</param> /// <param name="recipient">Recipient.</param> /// <param name="subject">Email subject.</param> /// <param name="bodyHtml">Email body.</param> public static void SendRecoveryPasswordLink(UserConnection userConnection, string recipient, string subject, string bodyHtml) { if (userConnection.GetIsFeatureEnabled("UseEmailSenderForSelfReg")) { EmailMessage emailMessage = CreateEmailMessage(userConnection, recipient, bodyHtml, subject); HtmlEmailMessageSender sender = GetEmailSender(userConnection); sender.Send(emailMessage, true); } else { var credentials = CreateMailCredentials(userConnection); var smtpUserName = credentials.UserName; var smtpClient = new Terrasoft.Mail.SmtpClient(userConnection); MailMessage message = smtpClient.CreateMessage(bodyHtml, subject, new[] { recipient }, smtpUserName, true, new Dictionary <Guid, Tuple <byte[], string> >()); smtpClient.SendMessage(message, credentials); } }
/// <summary> /// Send registration confirmation email. /// </summary> /// <param name="userConnection">User connection.</param> /// <param name="contactId">Contact identifier.</param> /// <param name="confirmRegistrationUrl">Confirmation registration url.</param> public static void SendEmail(UserConnection userConnection, Guid contactId, string confirmRegistrationUrl) { if (confirmRegistrationUrl.IsNullOrEmpty()) { string errorMessage = GetLocalizableString(userConnection, "LinkNotExist"); throw new ArgumentNullOrEmptyException(errorMessage, null); } string contactEmail = GetContactEmail(userConnection, contactId); var esq = new EntitySchemaQuery(userConnection.EntitySchemaManager, "EmailTemplate"); esq.AddColumn("Subject"); esq.AddColumn("Body"); esq.AddColumn("IsHtmlBody"); esq.AddColumn("Macros"); Guid registrationEmailTemplateId = GetRegistrationEmailTemplateId(userConnection); var template = (EmailTemplate)esq.GetEntity(userConnection, registrationEmailTemplateId); if (template == null) { string errorMessage = GetLocalizableString(userConnection, "EmailTemplateNotFound"); throw new ArgumentNullOrEmptyException(errorMessage, null); } var body = ReplaceRegistrationUrl(userConnection, contactId, confirmRegistrationUrl, template); if (userConnection.GetIsFeatureEnabled("UseEmailSenderForSelfReg")) { SendWithEmailSender(userConnection, contactEmail, body, template); } else { var credentials = CreateMailCredentials(userConnection); var smtpUserName = credentials.UserName; var attachments = GetEmailAttachmentsFromTemplate(registrationEmailTemplateId, userConnection); var smtpClient = new Terrasoft.Mail.SmtpClient(userConnection); var message = smtpClient.CreateMessage(body, template.Subject, new[] { contactEmail }, smtpUserName, template.IsHtmlBody, attachments); smtpClient.SendMessage(message, credentials); } }