コード例 #1
0
ファイル: EmailSender.cs プロジェクト: rohanbaraskar/Projects
        /// <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();
        }
コード例 #2
0
        /// <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();
        }
コード例 #3
0
ファイル: EmailSender.cs プロジェクト: rohanbaraskar/Projects
 /// <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);
     }
 }
コード例 #4
0
 /// <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);
     }
 }