Пример #1
0
        private void SendEmail()
        {
            EmailEntity entity = new EmailEntity();
            entity.Body = Common.Mail_Body;
            entity.Subject = Common.Mail_Subject;
            entity.Email_Recipient = Common.GetEmailRecipient();
            entity.Email_Attachments = Common.Attachment_List;
            entity.Host = Common.Mail_Host;
            entity.Port = Convert.ToInt32(Common.Mail_Port);
            entity.TimeOut = Convert.ToInt32(Common.Mail_TimeOut);

            EmailHelper.Send(entity);
        }
Пример #2
0
        public static void Send(EmailEntity entity)
        {
            try
            {
                SmtpClient smtp = new SmtpClient();
                smtp.Host = entity.Host;
                smtp.Port = entity.Port;
                smtp.Timeout = entity.TimeOut;

                System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                foreach (string email in entity.Email_Recipient)
                {
                    message.To.Add(email);
                }
                message.From = new MailAddress(Common.Mail_From, "", System.Text.Encoding.UTF8);
                message.Subject = entity.Subject;
                message.SubjectEncoding = System.Text.Encoding.UTF8;
                message.Body = entity.Body;

                System.Net.Mail.Attachment attachment;
                foreach (var attch in entity.Email_Attachments)
                {
                    if (attch != null)
                    {
                        attachment = new System.Net.Mail.Attachment(attch);
                        message.Attachments.Add(attachment);
                    }
                }
                message.BodyEncoding = System.Text.Encoding.UTF8;
                message.IsBodyHtml = true;
                message.Priority = MailPriority.Normal;

                smtp.Send(message);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }