Example #1
0
        public static void SendEmail(EmailSenderData emailData)
        {
            MailMessage mail = new MailMessage();
            SmtpClient smtpServer = new SmtpClient(emailData.SmtpClient);
            smtpServer.Port = 25;
            mail.From = new MailAddress(emailData.FromEmail);

            foreach (string currentEmail in emailData.Emails)
            {
                mail.To.Add(currentEmail);
            }
            mail.Subject = emailData.Subject;
            mail.IsBodyHtml = true;
            mail.Body = emailData.EmailBody;

            if (emailData.AttachmentPath != null)
            {                
                foreach (string currentPath in emailData.AttachmentPath)
                {
                    Attachment  attachment = new Attachment(currentPath);
                    mail.Attachments.Add(attachment);                    
                }               
                smtpServer.Send(mail);
                DisposeAllAttachments(mail);
            }
            else
            {
                smtpServer.Send(mail);
            }

            mail.Dispose();
            smtpServer.Dispose();
        }
Example #2
0
        public static void SendEmail(EmailSenderData emailData)
        {
            MailMessage mail       = new MailMessage();
            SmtpClient  smtpServer = new SmtpClient(emailData.SmtpClient);

            smtpServer.Port = 25;
            mail.From       = new MailAddress(emailData.FromEmail);

            foreach (string currentEmail in emailData.Emails)
            {
                mail.To.Add(currentEmail);
            }
            mail.Subject    = emailData.Subject;
            mail.IsBodyHtml = true;
            mail.Body       = emailData.EmailBody;

            if (emailData.AttachmentPath != null)
            {
                foreach (string currentPath in emailData.AttachmentPath)
                {
                    Attachment attachment = new Attachment(currentPath);
                    mail.Attachments.Add(attachment);
                }
                smtpServer.Send(mail);
                DisposeAllAttachments(mail);
            }
            else
            {
                smtpServer.Send(mail);
            }

            mail.Dispose();
            smtpServer.Dispose();
        }