Beispiel #1
0
        public static string SendEmail(NotificationEmailItem emailItem)
        {
            //return SendEmail(emailItem.DisplayName, emailItem.From, emailItem.To, emailItem.CC, emailItem.BCC, emailItem.Subject, emailItem.Body, emailItem.ReplyTo, emailItem.AttachmentFiles);

            SmtpClient smtp = new SmtpClient(smtpServer);

            //smtp.EnableSsl = true;

            if (smtpServer != null)
            {
                smtp.Host = smtpServer;
                smtp.Port = port;
                smtp.UseDefaultCredentials = defaultCredentials;
            }

            if (!defaultCredentials)
            {
                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(username, password);
                smtp.Credentials = credentials;
            }

            if (!string.IsNullOrEmpty(ConfigurationManager.AppSettings["TestEmail"]))
            {
                emailItem.Body += emailItem.To;
                emailItem.To    = ConfigurationManager.AppSettings["TestEmail"];
            }

            using (MailMessage mailMessage = emailItem.MailMessage)
            {
                //Note: When you make "IsBodyHtml" to true make  ValidateRequest="false" in page derective to make HTML content passed.
                mailMessage.IsBodyHtml = true;
                //mailMessage.Headers.Add("Content-Type", "text/html; charset=windows-1251");

                try
                {
                    smtp.Send(mailMessage);
                    return(string.Empty);
                }
                catch (Exception ex)
                {
                    throw ex;
                    //return LogManager.GetErrorText(ex);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sends the email.
        /// </summary>
        /// <param name="displayName">The display name.</param>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="cc">The cc.</param>
        /// <param name="bcc">The BCC.</param>
        /// <param name="subject">The subject.</param>
        /// <param name="body">The body.</param>
        /// <param name="replyTo">The reply to.</param>
        /// <returns></returns>
        public static string SendEmail(string displayName, string from, string to, string cc, string bcc, string subject, string body, string replyTo, string[] attachmentFiles = null)
        {
            NotificationEmailItem emailItem = new NotificationEmailItem
            {
                From            = from,
                DisplayName     = displayName,
                To              = to,
                CC              = cc,
                BCC             = bcc,
                ReplyTo         = replyTo,
                AttachmentFiles = attachmentFiles,

                Subject = subject,
                Body    = body
            };

            return(SendEmail(emailItem));
        }