예제 #1
0
파일: SmtpBox.cs 프로젝트: 0anion0/IBN
        /// <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);
            }
        }
예제 #2
0
파일: MailMessage.cs 프로젝트: 0anion0/IBN
        /// <summary>
        /// Creates the address header value.
        /// </summary>
        /// <param name="address">The address.</param>
        /// <returns></returns>
        private static string CreateAddressHeaderValue(MailAddress address)
        {
            StringBuilder builder = new StringBuilder();

            if (!string.IsNullOrEmpty(address.DisplayName))
            {
                builder.Append("\"");
                builder.Append(EncodeHeaderValue(address.DisplayName.Replace("\"", "\\\"")));
                builder.Append("\" ");
            }

            builder.Append("<");
            builder.Append(address.Address);
            builder.Append(">");

            return builder.ToString();
        }