Beispiel #1
0
        /// <summary>
        /// Sends the test email.
        /// </summary>
        /// <param name="smtpBoxId">The SMTP box id.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="htmlBody">The HTML body.</param>
        /// <param name="completeCheckPageUrl">The complete check page URL.</param>
        public static void SendTestEmail(int smtpBoxId, string subject, string htmlBody, string completeCheckPageUrl)
        {
            if (subject == null)
                throw new ArgumentNullException("subject");
            if (htmlBody == null)
                throw new ArgumentNullException("htmlBody");
            if (completeCheckPageUrl == null)
                throw new ArgumentNullException("completeCheckPageUrl");

            SmtpBoxRow row = new SmtpBoxRow(smtpBoxId);

            // Reset Check params
            row.Checked = false;
            row.CheckUid = Guid.NewGuid();

            row.Update();

            // Create Complete Back Link
            string backLink = completeCheckPageUrl + "?uid=" + row.CheckUid.ToString();

            SmtpClient client = SmtpClientUtility.CreateSmtpClient(new SmtpBox(row));

            string to = Security.CurrentUser.Email;

            // Create Mail Message
            MailMessage tesMsg = new MailMessage();

            MailAddress currentUser = new MailAddress(to, Security.CurrentUser.DisplayName);

            tesMsg.To.Add(currentUser);
            tesMsg.From = currentUser;
            tesMsg.Subject = subject;

            tesMsg.IsBodyHtml = true;
            tesMsg.Body = htmlBody + "<br/><a href='" + backLink + "'>" + backLink + "</a>";

            client.Send(tesMsg);

            if (!string.IsNullOrEmpty(tesMsg.ErrorMessage))
            {
                throw new SmtpException(tesMsg.ErrorMessage);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Copies the email entity to mail message.
        /// </summary>
        /// <param name="message">The message.</param>
        /// <returns></returns>
        private MailMessage CopyEmailEntityToMailMessage(EmailEntity message)
        {
            MailMessage outputMessage = new MailMessage();

            outputMessage.Subject = message.Subject;
            outputMessage.From = EmailUtil.CreateMailAddress(message.From);
            outputMessage.To.Add(EmailUtil.CreateMailAddress(message.To));

            if (!string.IsNullOrEmpty(message.MessageContext))
            {
                outputMessage.MessageContent = message.MessageContext;
            }
            else
            {
                outputMessage.IsBodyHtml = true;
                outputMessage.Body = message.HtmlBody;
            }
            return outputMessage;
        }