コード例 #1
0
 /// <summary>
 /// Загрузка файла
 /// </summary>
 /// <param name="fileName">Путь к файлу</param>
 /// <param name="db">БД</param>
 public string ImportDxlFile(string fileName, NotesDatabase db)
 {
     NotesStream      = db.Parent.CreateStream();
     NotesDxlImporter = db.Parent.CreateDXLImporter();
     if (!NotesStream.Open(fileName))
     {
         Loggers.Log4NetLogger.Error(new Exception("Невозможно открыть файл " + fileName));
         return(null);
     }
     //notesDXLImporter.InputValidationOption = VALIDATIONOPTION.VALIDATE_NEVER;
     NotesDxlImporter.ACLImportOption    = DXLIMPORTOPTION.DXLIMPORTOPTION_UPDATE_ELSE_IGNORE;
     NotesDxlImporter.DesignImportOption = DXLIMPORTOPTION.DXLIMPORTOPTION_REPLACE_ELSE_CREATE;
     NotesDxlImporter.ReplicaRequiredForReplaceOrUpdate = false;
     NotesDxlImporter.DocumentImportOption  = DXLIMPORTOPTION.DXLIMPORTOPTION_UPDATE_ELSE_CREATE;
     NotesDxlImporter.ExitOnFirstFatalError = true;
     try
     {
         NotesDxlImporter.Import(NotesStream, db);
         string text = NotesDxlImporter.GetFirstImportedNoteId();
         NotesStream.Truncate();
         NotesStream.Close();
         return(text);
     }
     catch (Exception e)
     {
         Loggers.Log4NetLogger.Error(new Exception(NotesDxlImporter.Log));
         Loggers.Log4NetLogger.Error(new Exception(NotesDxlImporter.LogComment));
         Loggers.Log4NetLogger.Error(e);
     }
     finally
     {
         Dispose();
     }
     return(null);
 }
コード例 #2
0
ファイル: Messenger.cs プロジェクト: dankovska/Ajour-1
        private static void SendUsingLotusNotes(string[] mailingList, IMessage message)
        {
            string serverName = WebConfigurationManager.AppSettings["LotusNotesServerName"];
            string mailFile   = WebConfigurationManager.AppSettings["LotusNotesMailFileName"];
            string password   = WebConfigurationManager.AppSettings["LotusNotesPassword"];

            string[] sendTo      = mailingList;
            string[] copyTo      = { };
            string   replyTo     = message.ReplyTo;
            string   blindCopyTo = "";
            string   subject     = message.Subject;

            //Create new notes session
            NotesSession notesSession = new NotesSession();

            notesSession.Initialize(password);

            //Get and open NotesDataBase
            NotesDatabase notesDataBase = notesSession.GetDatabase(serverName, mailFile, false);

            if (!notesDataBase.IsOpen)
            {
                notesDataBase.Open();
            }

            //Create the notes document
            NotesDocument notesDocument = notesDataBase.CreateDocument();

            //Set document type
            notesDocument.ReplaceItemValue("Form", "Memo");

            //Set notes memo fields (To: CC: Bcc: Subject etc)
            notesDocument.ReplaceItemValue("SendTo", sendTo);
            notesDocument.ReplaceItemValue("CopyTo", copyTo);
            notesDocument.ReplaceItemValue("BlindCopyTo", blindCopyTo);
            notesDocument.ReplaceItemValue("ReplyTo", replyTo);
            notesDocument.ReplaceItemValue("Subject", subject);

            //Set notes Body as HTML
            NotesStream notesStream = notesSession.CreateStream();

            notesStream.WriteText(message.Body);
            notesStream.WriteText("");
            notesStream.WriteText(message.Link);

            NotesMIMEEntity mimeItem = notesDocument.CreateMIMEEntity("Body");

            mimeItem.SetContentFromText(notesStream, "text/html; charset=UTF-8", MIME_ENCODING.ENC_NONE);

            notesDocument.Send(false);
        }
コード例 #3
0
        /// <summary>
        /// Рассылка писем если пришло Html В случае если зашло Html
        /// </summary>
        /// <param name="mailOutlook">Письма заступившие</param>
        /// <param name="arrayUsers">Рассылка пользователям</param>
        public void SendMailMimeHtml(MailLotusOutlookIn mailOutlook, List <string> arrayUsers)
        {
            Db.LotusConnectedDataBaseServer(Config.LotusServer, Config.LotusMailSend);
            NotesStream = Db.Db.Parent.CreateStream();
            Document    = Db.Db.CreateDocument();
            try
            {
                if (Db.Db == null)
                {
                    throw new InvalidOperationException("Фатальная ошибка нет соединения с сервером!");
                }
                Db.DeleteDataBaseAllMailSizeWarning();
                Document.AppendItemValue("Subject", "От кого: " + mailOutlook.MailAdress + " Тема: " + mailOutlook.SubjectMail);
                Document.AppendItemValue("Recipients", Db.Session.UserName);
                Document.AppendItemValue("OriginalTo", Db.Session.UserName);
                Document.AppendItemValue("From", Db.Session.UserName);
                Document.AppendItemValue("OriginalFrom", Db.Session.UserName);
                Document.AppendItemValue("SendTo", arrayUsers.ToArray());

                var mimeEntity = Document.CreateMIMEEntity();

                var mimeHeader = mimeEntity.CreateHeader("MIME-Version");
                mimeHeader.SetHeaderVal("1.0");

                mimeHeader = mimeEntity.CreateHeader("Content-Type");
                mimeHeader.SetHeaderValAndParams("multipart/mixed");

                var mimeChild = mimeEntity.CreateChildEntity();
                NotesStream.WriteText(mailOutlook.Body);

                mimeChild.SetContentFromText(NotesStream, "text/html;charset=\"utf-8\"", MIME_ENCODING.ENC_NONE);
                mimeChild = mimeEntity.CreateChildEntity();

                if (File.Exists(mailOutlook.FullPathFile))
                {
                    NotesStream.Truncate();
                    NotesStream.Open(mailOutlook.FullPathFile);
                    mimeHeader = mimeChild.CreateHeader("Content-Disposition");
                    mimeHeader.SetHeaderVal($"attachment; filename=\"{mailOutlook.NameFile}\"");
                    mimeChild.SetContentFromBytes(NotesStream, $"application/zip; name=\"{mailOutlook.NameFile}\"", MIME_ENCODING.ENC_IDENTITY_BINARY);
                }
                Document.CloseMIMEEntities(true);
                Db.Db.Parent.ConvertMime = true;
                if (Document.ComputeWithForm(true, false))
                {
                    Document.Save(true, true);
                    Document.Send(false);
                    NotesStream.Truncate();
                    NotesStream.Close();
                }
            }
            catch (Exception e)
            {
                Loggers.Log4NetLogger.Error(new Exception("В рассылке Html письма возникла ошибка!"));
                Loggers.Log4NetLogger.Error(e);
            }
            finally
            {
                if (Document != null)
                {
                    Marshal.ReleaseComObject(Document);
                }
                Document = null;
                if (NotesStream != null)
                {
                    Marshal.ReleaseComObject(NotesStream);
                }
                NotesStream = null;
            }
        }
コード例 #4
0
        public string SendMail(MailBody mailBody, MailSettings mailSettings)
        {
            _MailBody = mailBody;
            InitSettings(mailSettings);

            Validation();
            NotesSession  ns;
            NotesDatabase ndb;

            try
            {
                ns = new NotesSession();
                ns.Initialize(_Password);
                //初始化NotesDatabase
                ndb = ns.GetDatabase(_SMTPHost, "names.nsf", false);

                NotesDocument doc = ndb.CreateDocument();

                doc.ReplaceItemValue("Form", "Memo");

                //收件人信息
                doc.ReplaceItemValue("SendTo", ConvertToString(_MailBody.MailTo));

                if (_MailBody.MailCc != null && _MailBody.MailCc.Count > 0)
                {
                    doc.ReplaceItemValue("CopyTo", ConvertToString(_MailBody.MailCc));
                }

                if (_MailBody.MailBcc != null && _MailBody.MailBcc.Count > 0)
                {
                    doc.ReplaceItemValue("BlindCopyTo", ConvertToString(_MailBody.MailBcc));
                }

                //邮件主题
                doc.ReplaceItemValue("Subject", _MailBody.Subject);

                //邮件正文
                if (_MailBody.IsHtmlBody)
                {
                    NotesStream body = ns.CreateStream();
                    body.WriteText(_MailBody.Body, EOL_TYPE.EOL_PLATFORM);
                    NotesMIMEEntity mime = doc.CreateMIMEEntity("Body");
                    mime.SetContentFromText(body, "text/HTML;charset=gb2312", MIME_ENCODING.ENC_NONE);
                    body.Truncate();
                }
                else
                {
                    NotesRichTextItem rt = doc.CreateRichTextItem("Body");
                    rt.AppendText(_MailBody.Body);
                }

                //NotesRichTextItem rt = doc.CreateRichTextItem("Body");
                //if (_MailBody.IsHtmlBody)
                //{
                //    NotesRichTextStyle richtextStyle = ns.CreateRichTextStyle();
                //    richtextStyle.PassThruHTML = 1;
                //    rt.AppendStyle(richtextStyle);
                //}
                //rt.AppendText(_MailBody.Body);

                //附件
                //if (_MailBody.MailAttachments != null)
                //{
                //    NotesRichTextItem attachment = doc.CreateRichTextItem("attachment");
                //    foreach (MailAttachment a in _MailBody.MailAttachments)
                //    {
                //        if (!string.IsNullOrEmpty(a.Location))
                //        {
                //            attachment.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", a.Location, "attachment");
                //        }
                //    }
                //}
                //发送邮件
                object obj = doc.GetItemValue("SendTo");
                doc.Send(false, ref obj);
                doc = null;
                return("");
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    HandleMailLogs(ex.Message + "内部错误信息为:null");
                }
                else
                {
                    HandleMailLogs(ex.Message + "内部错误信息为:" + ex.InnerException.Message);
                }
                return("发送邮件失败");
            }
            finally
            {
                ndb = null;
                ns  = null;
                RecordTheMail();
            }
        }
コード例 #5
0
ファイル: SendMail.cs プロジェクト: zzz1985xxxwl/bjl_hrmis
        public string Send(MailBody mailBody)
        {
            _MailBody = mailBody;
            InitSettings();
            Validation();
            NotesSession  ns;
            NotesDatabase ndb;

            try
            {
                ns = new NotesSession();
                ns.Initialize(_MailSet.Password);
                //初始化NotesDatabase
                ndb = ns.GetDatabase(_MailSet.SMTPHost, "names.nsf", false);

                NotesDocument doc = ndb.CreateDocument();

                doc.ReplaceItemValue("Form", "Memo");

                //收件人信息
                doc.ReplaceItemValue("SendTo", ConvertToString(_MailBody.MailTo));

                if (_MailBody.MailCc != null && _MailBody.MailCc.Count > 0)
                {
                    doc.ReplaceItemValue("CopyTo", ConvertToString(_MailBody.MailCc));
                }

                if (_MailBody.MailBcc != null && _MailBody.MailBcc.Count > 0)
                {
                    doc.ReplaceItemValue("BlindCopyTo", ConvertToString(_MailBody.MailBcc));
                }

                //邮件主题
                doc.ReplaceItemValue("Subject", _MailBody.Subject);

                //邮件正文
                if (_MailBody.IsHtmlBody)
                {
                    NotesStream body = ns.CreateStream();
                    body.WriteText(_MailBody.Body, EOL_TYPE.EOL_PLATFORM);
                    NotesMIMEEntity mime = doc.CreateMIMEEntity("Body");
                    mime.SetContentFromText(body, "text/HTML;charset=gb2312", MIME_ENCODING.ENC_NONE);
                    body.Truncate();
                }
                else
                {
                    NotesRichTextItem rt = doc.CreateRichTextItem("Body");
                    rt.AppendText(_MailBody.Body);
                }

                //发送邮件
                object obj = doc.GetItemValue("SendTo");
                doc.Send(false, ref obj);
                doc = null;
                return("");
            }
            catch (Exception ex)
            {
                Log.Write(ex);
                return("发送邮件失败");
            }
            finally
            {
                ndb = null;
                ns  = null;
            }
        }