/// <summary> /// Sends the email. /// </summary> /// <param name="emailData">The email data.</param> public static void SendEmail(EmailMessageData emailData) { MailMessage mail = new MailMessage(); SmtpClient smtpServer = new SmtpClient(CurrentSmtpClient); smtpServer.Port = CurrentSmtpClientPort; 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; AddAttachmentsToEmail(emailData, mail); smtpServer.Send(mail); DisposeAllAttachments(mail); mail.Dispose(); smtpServer.Dispose(); }
/// <summary> /// Adds the attachments to email. /// </summary> /// <param name="emailData">The email data.</param> /// <param name="mail">The mail.</param> private static void AddAttachmentsToEmail(EmailMessageData emailData, MailMessage mail) { foreach (string currentPath in emailData.AttachmentPaths) { Attachment attachment = new Attachment(currentPath); mail.Attachments.Add(attachment); } }