/// <summary> /// Формирование модели для отправки по SMTP протоколу /// </summary> /// <param name="pathSaveFile">Путь сохранения вложенных в письма файлов на отправку</param> public List <MailLotusOutlookOut> SendMailOut(string pathSaveFile) { var mailLotusOutlookOut = new List <MailLotusOutlookOut>(); var publicFunction = new PublicFunctionInfo.PublicFunctionInfo(); Db.LotusConnectedDataBaseServer(Config.LotusServer, Config.LotusMailSend); if (Db.Db == null) { throw new InvalidOperationException("Фатальная ошибка нет соединения с сервером!"); } var docList = new List <string>(); try { NotesView = Db.GetViewLotus("$Inbox"); Document = NotesView.GetFirstDocument(); while (Document != null) { var mail = new MailLotusOutlookOut { IdMail = Document.UniversalID, MailAdressOut = Document.GetItemValue("Subject")[0].ToString(), Body = Document.GetItemValue("Body")[0].ToString() }; NotesRichTextItem bodyFileExtractMail = Document.GetFirstItem("Body") as NotesRichTextItem; var nameFileList = publicFunction.ExtractFile(bodyFileExtractMail, pathSaveFile); mail.FullPathListFile = nameFileList != null && nameFileList.Count > 0 ? string.Join(";", nameFileList) : null; mail.MailAdressIn = Document.GetItemValue("From")[0].ToString(); docList.Add(Document.UniversalID); mailLotusOutlookOut.Add(mail); Document = NotesView.GetNextDocument(Document); } } catch (Exception ex) { Loggers.Log4NetLogger.Error(ex); throw; } finally { if (Document != null) { Marshal.ReleaseComObject(Document); } Document = null; if (NotesView != null) { Marshal.ReleaseComObject(NotesView); } NotesView = null; } foreach (var unId in docList) { Document = Db.Db.GetDocumentByUNID(unId); if (Document == null) { throw new InvalidOperationException($"No document {unId}"); } Document.Remove(true); Marshal.ReleaseComObject(Document); } return(mailLotusOutlookOut); }
/// <summary> /// Отправка письма с почты /// </summary> /// <param name="mailOut">Отправка письма</param> public void AddModelMailOut(MailLotusOutlookOut mailOut) { Inventory.MailLotusOutlookOuts.Add(mailOut); Inventory.SaveChanges(); Loggers.Log4NetLogger.Info(new Exception("Сохранили письмо с УН " + mailOut.IdMail)); }