private void MailWithAttach(ReportExecuteLog log, string address, string[] files, string subjectSufix = null) { var message = new Mime(); var mainEntry = message.MainEntity; mainEntry.From = new AddressList { new MailboxAddress("АналитФармация", "*****@*****.**") }; mainEntry.To = new AddressList(); mainEntry.To.Parse(address); if (!string.IsNullOrEmpty(EMailSubject)) { mainEntry.Subject = EMailSubject; } if (!String.IsNullOrEmpty(subjectSufix)) { if (!String.IsNullOrEmpty(mainEntry.Subject)) { mainEntry.Subject += " "; } mainEntry.Subject += subjectSufix; } mainEntry.ContentType = MediaType_enum.Multipart_mixed; var textEntity = mainEntry.ChildEntities.Add(); textEntity.ContentType = MediaType_enum.Text_plain; textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; textEntity.DataText = String.Empty; foreach (var file in files) { AttachFile(mainEntry, file); } if (Testing) { Messages.Add(message); } else { var smtpId = SmtpClientEx.QuickSendSmartHostSMTPID(Settings.Default.SMTPHost, null, null, message); ProcessLog(smtpId, message.MainEntity.MessageID, address, log); } }
public static int Send(MailMessage message) { try { #if DEBUG message.To.Clear(); message.To.Add(GetDebugMail()); message.Bcc.Clear(); message.CC.Clear(); #endif var smtpid = SmtpClientEx.QuickSendSmartHostSMTPID(GetSmtpServer(), "", "", message); if (smtpid == null) { return(0); } return(smtpid.Value); } catch (Exception ex) { _log.Error("Не удалось отправить письмо", ex); } return(0); }