public static void AddMailFileOnException(MailSenderAttachment attachment) { if (_files == null) { _files = new MailSenderAttachmentList(); } _files.Add(attachment); }
public void SendWithImages(string fromEmail, string toEmail, string subject, string content, Image[] images, MailSenderAttachmentList files = null) { using (var msg = new MailMessage(fromEmail, toEmail, subject, content)) { msg.IsBodyHtml = true; msg.Priority = MailPriority.High; msg.BodyEncoding = Encoding.UTF8; var i = 0; foreach (var img in images) { var ms = new System.IO.MemoryStream(); img.Save(ms, ImageFormat.Jpeg); ms.Position = 0; var att = new Attachment(ms, $"{ Guid.NewGuid() }.jpg", "image/jpg"); att.ContentId = $"img_{i}"; msg.Attachments.Add(att); i++; } if (files != null) { foreach (var file in files) { var ms = new System.IO.MemoryStream(file.FileBuffer); var att = new Attachment(ms, file.Name, string.IsNullOrEmpty(file.MimeType) ? "application/octet-stream" : file.MimeType); msg.Attachments.Add(att); i++; } } _client.Send(msg); } }
public void SendWithFiles(string fromEmail, string toEmail, string subject, string content, MailSenderAttachmentList files) { using (var msg = new MailMessage(fromEmail, toEmail, subject, content)) { msg.IsBodyHtml = true; msg.Priority = MailPriority.High; msg.BodyEncoding = Encoding.UTF8; var i = 0; foreach (var file in files) { var ms = new System.IO.MemoryStream(file.FileBuffer); var att = new Attachment(ms, file.Name, string.IsNullOrEmpty(file.MimeType) ? "application/octet-stream" : file.MimeType); att.ContentId = $"file_{i}"; msg.Attachments.Add(att); i++; } _client.Send(msg); } }