/************************************************************************/ /* Sending emails by regular code */ /************************************************************************/ public static MailMessage BuildMailMessage( string fromEmail, string fromName, string replyToEmail, string replyToName, string to, string cc, string bcc, string subject, string body, string[] attachmentPaths, MailPriority?mailPriority, List <string> lstTo = null) { MailMessage message = new MailMessage(); message.From = new MailAddress(fromEmail, fromName); if (!string.IsNullOrEmpty(replyToEmail)) { message.ReplyToList.Add(new MailAddress(replyToEmail, replyToName)); } if (lstTo != null) { foreach (string item in lstTo) { Mail.AddAddress(item, message.Bcc); } } else { Mail.AddAddress(to, message.To); } if (!string.IsNullOrEmpty(cc)) { Mail.AddAddress(cc, message.CC); } if (!string.IsNullOrEmpty(bcc)) { Mail.AddAddress(bcc, message.Bcc); } message.Subject = subject; message.SubjectEncoding = System.Text.Encoding.UTF8; message.Priority = mailPriority ?? MailPriority.Normal; message.IsBodyHtml = true; message.Body = body; message.BodyEncoding = System.Text.Encoding.UTF8; // Create attachments if ((attachmentPaths != null) && (attachmentPaths.Length > 0)) { foreach (string attachmentPath in attachmentPaths) { // MailAttachment likes fully-qualified file names, use FileInfo to // get them. FileInfo fileInfo = new FileInfo(attachmentPath); if (fileInfo.Exists) { message.Attachments.Add(new Attachment(fileInfo.FullName)); } else { Trace.TraceError("Attachment not found: {0}", fileInfo.FullName); } } } return(message); }