Пример #1
0
        public EmailSender()
        {
            Headers      = new Dictionary <string, string>();
            ErrorMessage = string.Empty;

            SmtpSettings = new MailSmtpSettings();
            SendSettings = new MailSendSettings();
        }
Пример #2
0
        /// <summary>
        /// Thuc hien cong viec gui mot Email
        /// </summary>
        /// <param name="smtpSettings">Thong so thiet lap truoc khi gui mail</param>
        /// <param name="from">Dia chi email gui</param>
        /// <param name="to">Dia chi email nhan</param>
        /// <param name="cc">Cac dia chi cung tham gia</param>
        /// <param name="bcc">Cac email khac can biet</param>
        /// <param name="subject">Chu de</param>
        /// <param name="messageBody">Noi dung email</param>
        /// <param name="html">Dinh dang HTML hay khong</param>
        /// <param name="priority">Muc do uu tien</param>
        /// <param name="filePath">Duong dan file gui kem</param>
        public static bool SendEmail(MailSmtpSettings smtpSettings,
                                     string fromEmail, string fromName,
                                     string toEmails, string ccEmails, string bccEmails,
                                     string emailSubject, string emailBody,
                                     bool isHtml, string priority, string filePaths,
                                     out string errorMessage)
        {
            bool result = false;

            errorMessage = string.Empty;

            using (EmailSender emailEngine = new EmailSender())
            {
                emailEngine.SmtpSettings = smtpSettings;

                emailEngine.SendSettings.SenderEmail = fromEmail;
                emailEngine.SendSettings.SenderName  = fromName;
                emailEngine.SendSettings.Recipient   = toEmails;
                emailEngine.SendSettings.CC          = ccEmails;
                emailEngine.SendSettings.BCC         = bccEmails;
                emailEngine.SendSettings.Subject     = emailSubject;
                emailEngine.SendSettings.Message     = emailBody;
                emailEngine.SendSettings.Priority    = priority;
                emailEngine.SendSettings.Encoding    = Encoding.UTF8;

                emailEngine.SendSettings.Attachments = filePaths;
                if (isHtml)
                {
                    emailEngine.SendSettings.ContentType = "text/html";
                }

                result       = emailEngine.SendMail();
                errorMessage = emailEngine.ErrorMessage;
            }

            return(result);
        }