Ejemplo n.º 1
0
        /// <summary>
        /// Lotus Send E-Mail
        /// </summary>
        /// <param name="sendTo"></param>
        /// <param name="copyTo"></param>
        /// <param name="subject"></param>
        /// <param name="content"></param>
        /// Owner:Andy Gao 2011-08-22 09:32:50
        public static void LotusSendEMail(string[] sendTo, string[] copyTo, string subject, string content)
        {
            NotesSession ns = new NotesSession();

            ns.Initialize(lotusPassword);

            NotesDatabase ndb = ns.GetDatabase(lotusServer, lotusFile, false);

            NotesDocument doc = ndb.CreateDocument();

            doc.ReplaceItemValue(LOTUS_SENDTO, sendTo);
            doc.ReplaceItemValue(LOTUS_COPYTO, copyTo);
            doc.ReplaceItemValue(LOTUS_SUBJECT, subject);

            NotesRichTextItem rti = doc.CreateRichTextItem(LOTUS_BODY);

            rti.AppendText(content);

            object recipients = doc.GetItemValue(LOTUS_SENDTO);

            doc.Send(false, ref recipients);

            Marshal.ReleaseComObject(rti);
            Marshal.ReleaseComObject(doc);
            Marshal.ReleaseComObject(ndb);
            Marshal.ReleaseComObject(ns);

            rti = null;
            doc = null;
            ndb = null;
            ns  = null;
        }
Ejemplo n.º 2
0
        public void SendMail()
        {
            try
            {
                NotesSession ns = new NotesSessionClass();

                ns.Initialize(pwd);
                NotesDatabase ndb = ns.GetDatabase(serverName, nsfFile, false);

                NotesDocument doc = ndb.CreateDocument();
                doc.ReplaceItemValue("Form", "Memo");
                string[] sendtoString = mailTo.ToArray();
                doc.ReplaceItemValue("SendTo", sendtoString);
                doc.ReplaceItemValue("Subject", subject);
                NotesRichTextItem rt = doc.CreateRichTextItem("Body");
                rt.AppendText(body);

                if ((attFileName != null) && (attFileName.Count > 0))
                {
                    NotesRichTextItem item = doc.CreateRichTextItem("attachment");
                    foreach (string att in attFileName)
                    {
                        item.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", att, "attachment");
                    }
                }

                object obj = doc.GetItemValue("SendTo");
                doc.Send(false, ref obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Sends the via notes.
        /// </summary>
        /// <param name="settings">Any settings needed</param>
        /// <param name="month">The month.</param>
        /// <param name="year">The year.</param>
        /// <param name="fullFilename">The full filename.</param>
        /// <param name="emailAddress">The email address.</param>
        /// <param name="password">The password required to submit</param>
        public void Send(Settings settings, string month, string year, string fullFilename, string emailAddress, SecureString password = null)
        {
            // Two digit month and four digit year
            NotesSession session = new NotesSession();

            session.Initialize();
            NotesDatabase database = session.GetDatabase("Pride/Tessella", "mail\\waldm.nsf");

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

            NotesDocument document = database.CreateDocument();

            document.ReplaceItemValue("Form", "Memo");
            document.ReplaceItemValue("Sendto", emailAddress);
            string subject = settings.StaffID + " " + month + "/" + year;

            document.ReplaceItemValue("Subject", subject);

            NotesRichTextItem attachment = document.CreateRichTextItem("Attachment");

            attachment.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, string.Empty, fullFilename, "Attachment");

            document.SaveMessageOnSend = true;
            document.ReplaceItemValue("PostedDate", DateTime.Now);
            document.Send(false, emailAddress);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 发送新信件
        /// </summary>
        /// <param name="pSupervisors">抄送人</param>
        /// <param name="pSendSecret">密送人</param>
        /// <param name="pSubject">主题</param>
        /// <param name="strMailContent">内容</param>
        /// <returns></returns>
        public bool SendMailInfo(object pSupervisors, object pSendSecret, object pSubject, string strMailContent)
        {
            bool              bResult       = false;
            NotesDocument     pMailDocument = null;
            NotesRichTextItem pContentItem  = null;

            try
            {
                pMailDocument = this.pNotesDatabase.CreateDocument();

                pMailDocument.ReplaceItemValue("Form", "Memo");
                pMailDocument.ReplaceItemValue("CopyTo", pSupervisors);     //抄送
                pMailDocument.ReplaceItemValue("BlindCopyTo", pSendSecret); //密送
                pMailDocument.ReplaceItemValue("Subject", pSubject);
                pMailDocument.ReplaceItemValue("PostedDate", DateTime.Now.ToString());

                pContentItem = pMailDocument.CreateRichTextItem("Body");
                pContentItem.AppendText(strMailContent);

                object pSendOwner = this._strUserName;
                pMailDocument.Send(false, ref pSendOwner);

                bResult = true;
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;

                bResult = false;
            }
            finally
            {
                if (pContentItem != null)
                {
                    Marshal.ReleaseComObject(pContentItem);
                }

                if (pMailDocument != null)
                {
                    Marshal.ReleaseComObject(pMailDocument);
                }

                pContentItem  = null;
                pMailDocument = null;
            }

            return(bResult);
        }
Ejemplo n.º 5
0
        public void SendMailIBM(string mailTo, List <string> mailCC, string mailTitle, string IDyc, string date, string username, string mbody)
        {
            try
            {
                NotesSession nSession = new NotesSession();
                nSession.Initialize("12345678");
                NotesDatabase nDatabase  = nSession.GetDatabase("meiko_notes_hanoi2/SOUMU", "mail\\hrsystem.nsf");
                NotesDocument nDocument  = nDatabase.CreateDocument();
                string[]      recipients =
                { "tu.nguyenduy/SOUMU", "*****@*****.**" };

                nDocument.ReplaceItemValue("Form", "Memo");
                nDocument.ReplaceItemValue("SentTo", recipients);                    //To field
                nDocument.ReplaceItemValue("Subject", "Message subject");            //message subject
                nDocument.ReplaceItemValue("Body", "Something in the message body"); //set body text
                nDocument.SaveMessageOnSend = true;                                  //save message after it's sent
                nDocument.Send(false, recipients);                                   //send
            }
            catch
            {
            }
        }
Ejemplo n.º 6
0
        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);
        }
 private void SetMailAsRead(NotesDocument profileDocument, IDocumentCollection documentCollection)
 {
     try
     {
         profileDocument.ReplaceItemValue("UntilTime", documentCollection.UntilTime);
         profileDocument.Save(true, true, true);
     }
     catch (Exception e)
     {
         Logger logger = LogManager.GetCurrentClassLogger();
         logger.Log(LogLevel.Error, e);
     }
 }
Ejemplo n.º 8
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();
            }
        }
Ejemplo n.º 9
0
        public void Pub()
        {
            try
            {
                NotesSession ns = new NotesSessionClass();
                ns.Initialize(pwd);
                NotesDatabase ndb = ns.GetDatabase(serverName, nsfFile, false);

                NotesDocument doc = ndb.CreateDocument();

                doc.ReplaceItemValue("Form", "中央气象台产品记录");

                doc.ReplaceItemValue("dbname_11", "juece.nsf");
                doc.ReplaceItemValue("dbname_12", "juece.nsf");
                doc.ReplaceItemValue("dbname_13", "juece.nsf");
                doc.ReplaceItemValue("dbname_21", "juece.nsf");
                doc.ReplaceItemValue("dbname_22", "juece.nsf");
                doc.ReplaceItemValue("dbname_222", "juece.nsf");
                doc.ReplaceItemValue("dbname_23", "juece.nsf");
                doc.ReplaceItemValue("dbname_24", "juece.nsf");
                doc.ReplaceItemValue("dbname_30", "juece.nsf");
                doc.ReplaceItemValue("doctype", "OCX");
                doc.ReplaceItemValue("Encrypt", "0");

                doc.ReplaceItemValue("img", "");
                doc.ReplaceItemValue("issuetime", this.dateNum);
                doc.ReplaceItemValue("SendTo", "CMA决策");
                doc.ReplaceItemValue("SendTobyHub", "各省气象信息共享数据库");
                doc.ReplaceItemValue("sendOk", "0");
                doc.ReplaceItemValue("role", "周军");
                doc.ReplaceItemValue("role_1", "短期科");

                doc.ReplaceItemValue("标题域", this.Title);
                doc.ReplaceItemValue("标题域_1", this.Title);
                doc.ReplaceItemValue("部委", "0");
                doc.ReplaceItemValue("草稿", "0");
                doc.ReplaceItemValue("产品", "天气预报");
                doc.ReplaceItemValue("产品_1", "天气预报");
                doc.ReplaceItemValue("发布单位", "国家气象中心");
                doc.ReplaceItemValue("发布单位_1", "中央气象台");
                doc.ReplaceItemValue("发布单位_1_1", "中央气象台");
                doc.ReplaceItemValue("发布单位_2", "国家气象中心");
                doc.ReplaceItemValue("发布单位_e", "qxt");
                doc.ReplaceItemValue("发布时间", this.dateNum);
                doc.ReplaceItemValue("发布时间_1", this.datePy);
                doc.ReplaceItemValue("发布时间_2", this.dateNum);
                //doc.ReplaceItemValue("内容", this.Content);
                doc.ReplaceItemValue("日期1", this.dateNum);
                doc.ReplaceItemValue("状态", "1");

                if ((attFileName != null) && (attFileName.Count > 0))
                {
                    NotesRichTextItem item = doc.CreateRichTextItem("attachment");
                    foreach (string att in attFileName)
                    {
                        item.EmbedObject(EMBED_TYPE.EMBED_ATTACHMENT, "", att, "attachment");
                        doc.ReplaceItemValue("fname", System.IO.Path.GetFileName(att));
                    }
                }

                doc.ComputeWithForm(true, false);
                object obj = doc.GetItemValue("SendTo");
                doc.Send(false, ref obj);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 转发/回复信件
        /// </summary>
        /// <param name="pSupervisors">抄送人</param>
        /// <param name="pSendSecret">密送人</param>
        /// <param name="strNotesUID">原NotesID</param>
        /// <param name="strMailContent">内容</param>
        /// <returns></returns>
        public bool RelayMailInfo(object pSupervisors, object pSendSecret, string strNotesUID, string strMailContent)
        {
            bool          bResult         = false;
            NotesView     pParentView     = null;
            NotesDocument pParentDocument = null;

            try
            {
                if (this._strDataBase == "names.nsf")
                {
                    this.pNotesDatabase = this._pNotesSession.GetDatabase(this._strDomain, this._strDataBase, false);
                }

                if (this.pNotesDatabase == null)
                {
                    throw new Exception("不能打开数据库:" + this._strDataBase);
                }

                pParentView     = this.pNotesDatabase.GetView("($inbox)");
                pParentDocument = pParentView.GetFirstDocument();

                while (pParentDocument != null)
                {
                    if (pParentDocument.UniversalID == strNotesUID)
                    {
                        NotesDocument pRelayDocument  = pParentDocument.CreateReplyMessage(false);
                        string        strPrincipal    = (((object[])pParentDocument.GetItemValue("Principal"))[0] == null) ? "N/A" : ((object[])pParentDocument.GetItemValue("Principal"))[0].ToString();
                        string        strRelaySubject = (((object[])pParentDocument.GetItemValue("Subject"))[0] == null) ? "N/A" : ((object[])pParentDocument.GetItemValue("Subject"))[0].ToString();

                        pParentDocument.ReplaceItemValue("Form", "Reply");
                        pParentDocument.ReplaceItemValue("CopyTo", pSupervisors);     //抄送
                        pParentDocument.ReplaceItemValue("BlindCopyTo", pSendSecret); //密送
                        pParentDocument.ReplaceItemValue("Subject", "回复:" + strRelaySubject);
                        pParentDocument.ReplaceItemValue("PostedDate", DateTime.Now.ToString());
                        pParentDocument.ReplaceItemValue("Principal", "CN=netadmin/OU=网管部/OU=产品运营中心/O=runstar");
                        pParentDocument.ReplaceItemValue("Body", "");
                        pParentDocument.ReplaceItemValue("SSM_Agent", strNotesUID);

                        if (pParentDocument.HasItem("Reader"))
                        {
                            pParentDocument.ReplaceItemValue("Reader", "NO");
                        }

                        NotesRichTextItem pOldItem = (NotesRichTextItem)pParentDocument.GetFirstItem("Body");
                        pOldItem.AppendText(strMailContent);
                        pOldItem.AddNewLine(5, false);
                        pOldItem.AppendRTItem((NotesRichTextItem)pRelayDocument.GetFirstItem("Body"));

                        object pSendOwner = strPrincipal;//"孙露"
                        pParentDocument.Send(false, ref pSendOwner);

                        bResult = true;

                        Marshal.ReleaseComObject(pOldItem);
                        Marshal.ReleaseComObject(pRelayDocument);

                        pOldItem       = null;
                        pRelayDocument = null;
                        break;
                    }
                    else
                    {
                        bResult = false;

                        this.strMessage = "不能找到原始信件,原信件可能已删除,请新建一封信的信件给接收人!";
                    }

                    pParentDocument = pParentView.GetNextDocument(pParentDocument);
                }
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;

                bResult = false;
            }
            finally
            {
                if (pParentDocument != null)
                {
                    Marshal.ReleaseComObject(pParentDocument);
                }

                if (pParentView != null)
                {
                    Marshal.ReleaseComObject(pParentView);
                }

                pParentDocument = null;
                pParentView     = null;
            }

            return(bResult);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取新信件
        /// </summary>
        /// <returns></returns>
        public bool GetMailInfo()
        {
            bool          bResult       = false;
            NotesView     pMailView     = null;
            NotesDocument pMailDocument = null;
            int           iCount        = 0;

            try
            {
                if (this._strDataBase == "names.nsf")
                {
                    this.pNotesDatabase = this._pNotesSession.GetDatabase(this._strDomain, this._strDataBase, false);
                }

                if (this.pNotesDatabase == null)
                {
                    throw new Exception("不能打开数据库:" + this._strDataBase);
                }

                pMailView = this.pNotesDatabase.GetView("($inbox)");

                pMailDocument = pMailView.GetFirstDocument();
                Console.WriteLine("共计:" + pMailView.EntryCount.ToString());

                CustomDataCollection pMailStruct = new CustomDataCollection(StructType.CUSTOMDATA);

                while (pMailDocument != null)
                {
                    if (((object[])pMailDocument.GetItemValue("Reader"))[0].ToString() != "YES")
                    {
                        string strPUID        = string.Empty;
                        string strSubject     = (((object[])pMailDocument.ColumnValues)[5] == null) ? "N/A" : ((object[])pMailDocument.ColumnValues)[5].ToString();
                        string strSupervisors = (((object[])pMailDocument.GetItemValue("CopyTo")).Length == 0) ? "N/A" : ((object[])pMailDocument.GetItemValue("CopyTo"))[0].ToString();
                        string strSendTo      = (((object[])pMailDocument.GetItemValue("SendTo")).Length == 0) ? "N/A" : ((object[])pMailDocument.GetItemValue("SendTo"))[0].ToString();

                        if (strSendTo != "N/A")
                        {
                            for (int i = 0; i < ((object[])pMailDocument.GetItemValue("SendTo")).Length; i++)
                            {
                                strSupervisors = strSupervisors + ";" + ((object[])pMailDocument.GetItemValue("SendTo"))[i].ToString();
                            }
                        }

                        if (strSupervisors != "N/A")
                        {
                            for (int i = 1; i < ((object[])pMailDocument.GetItemValue("CopyTo")).Length; i++)
                            {
                                strSupervisors = strSupervisors + ";" + ((object[])pMailDocument.GetItemValue("CopyTo"))[i].ToString();
                            }
                        }

                        string strBody = ((object[])pMailDocument.GetItemValue("Body"))[0].ToString();

                        if (((object[])pMailDocument.GetItemValue("SSM_Agent"))[0].ToString().Length != 0)
                        {
                            strPUID = ((object[])pMailDocument.GetItemValue("SSM_Agent"))[0].ToString();
                        }
                        else if (((object[])pMailDocument.GetItemValue("SSM_Agent"))[0].ToString().Length == 0 && pMailDocument.ParentDocumentUNID == null)
                        {
                            strPUID = "N/A";
                        }
                        else
                        {
                            strPUID = pMailDocument.ParentDocumentUNID;
                        }

                        /*
                         * if (pMailDocument.HasItem("SMS Agent"))
                         * {
                         *  strPUID = ((object[])pMailDocument.GetItemValue("SMS Agent"))[0].ToString();
                         * }
                         * else if (!pMailDocument.HasItem("SMS Agent") && pMailDocument.ParentDocumentUNID == null)
                         * {
                         *  strPUID = "N/A";
                         * }
                         * else
                         * {
                         *  strPUID = pMailDocument.ParentDocumentUNID;
                         * }
                         */

                        //剔除--服务器正常和服务器一切正常
                        if (strSubject.IndexOf("服务器正常", StringComparison.CurrentCulture) > 0 || strSubject.IndexOf("服务器一切正常", StringComparison.CurrentCulture) > 0)
                        {
                            if (pMailDocument.HasItem("Reader"))
                            {
                                pMailDocument.ReplaceItemValue("Reader", "YES");
                            }
                            else
                            {
                                pMailDocument.AppendItemValue("Reader", "YES");
                            }

                            pMailDocument.Save(true, true, true);
                        }
                        else
                        {
                            pMailStruct.Add(DataField.NOTES_UID, DataFormat.STRING, pMailDocument.UniversalID);
                            pMailStruct.Add(DataField.NOTES_UID, DataFormat.STRING, strPUID);
                            pMailStruct.Add(DataField.NOTES_SUBJECT, DataFormat.STRING, strSubject);
                            pMailStruct.Add(DataField.NOTES_FROM, DataFormat.STRING, ((object[])pMailDocument.GetItemValue("Principal"))[0].ToString());
                            pMailStruct.Add(DataField.NOTES_DATE, DataFormat.STRING, ((object[])pMailDocument.ColumnValues)[2].ToString());
                            pMailStruct.Add(DataField.NOTES_SUPERVISORS, DataFormat.STRING, (strSupervisors == "") ? "N/A" : strSupervisors);
                            pMailStruct.Add(DataField.NOTES_CONTENT, DataFormat.STRING, (strBody == "") ? "N/A" : strBody);
                            try
                            {
                                pMailStruct.Add(DataField.NOTES_ATTACHMENTCOUNT, DataFormat.STRING, (((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects == null) ? "0" : ((object[])((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects).Length.ToString());
                            }
                            catch
                            {
                                pMailStruct.Add(DataField.NOTES_ATTACHMENTCOUNT, DataFormat.STRING, "信件内包含多个信件主体,请查阅自己的信箱!");
                            }
                            pMailStruct.AddRows();

                            //GlobalStruct[] pMailStruct = new GlobalStruct[8];

                            //pMailStruct[0].oFieldsName = "Notes_UID";
                            //pMailStruct[0].oFiledsTypes = "String";
                            //pMailStruct[0].oFieldValues = pMailDocument.UniversalID;

                            //pMailStruct[1].oFieldsName = "Notes_PUID";
                            //pMailStruct[1].oFiledsTypes = "String";
                            //pMailStruct[1].oFieldValues = strPUID; // (pMailDocument.ParentDocumentUNID == null) ? "N/A" : pMailDocument.ParentDocumentUNID;

                            //pMailStruct[2].oFieldsName = "Notes_Subject";
                            //pMailStruct[2].oFiledsTypes = "String";
                            //pMailStruct[2].oFieldValues = strSubject;

                            //pMailStruct[3].oFieldsName = "Notes_From";
                            //pMailStruct[3].oFiledsTypes = "String";
                            //pMailStruct[3].oFieldValues = ((object[])pMailDocument.GetItemValue("Principal"))[0].ToString(); //((object[])pMailDocument.ColumnValues)[1].ToString();

                            //pMailStruct[4].oFieldsName = "Notes_Date";
                            //pMailStruct[4].oFiledsTypes = "String";
                            //pMailStruct[4].oFieldValues = ((object[])pMailDocument.ColumnValues)[2].ToString();

                            //pMailStruct[5].oFieldsName = "Notes_Supervisors";
                            //pMailStruct[5].oFiledsTypes = "String";
                            //pMailStruct[5].oFieldValues = (strSupervisors == "") ? "N/A" : strSupervisors;

                            //pMailStruct[6].oFieldsName = "Notes_Content";
                            //pMailStruct[6].oFiledsTypes = "String";
                            //pMailStruct[6].oFieldValues = (strBody == "") ? "N/A" : strBody;

                            //pMailStruct[7].oFieldsName = "Notes_AttachmentCount";
                            //pMailStruct[7].oFiledsTypes = "String";
                            //try
                            //{
                            //    pMailStruct[7].oFieldValues = (((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects == null) ? "0" : ((object[])((NotesRichTextItem)pMailDocument.GetFirstItem("Body")).EmbeddedObjects).Length.ToString();
                            //}
                            //catch
                            //{
                            //    pMailStruct[7].oFieldValues = "信件内包含多个信件主体,请查阅自己的信箱!";
                            //}

                            this.pInfoList.Add(pMailStruct);

                            if (pMailDocument.HasItem("Reader"))
                            {
                                pMailDocument.ReplaceItemValue("Reader", "YES");
                            }
                            else
                            {
                                pMailDocument.AppendItemValue("Reader", "YES");
                            }

                            //pMailStruct = null;

                            pMailDocument.Save(true, true, true);
                            iCount++;
                        }
                    }

                    //pMailDocument.PutInFolder("历史纪录", false);

                    pMailDocument = pMailView.GetNextDocument(pMailDocument);

                    //if (pMailDocument != null)
                    //{
                    //    pMailView.GetPrevDocument(pMailDocument).Remove(false);
                    //}
                }

                this.pRecords = pMailStruct;
                bResult       = true;
            }
            catch (Exception ex)
            {
                this.strMessage = ex.Message;
                Console.WriteLine("丢失Notes个数" + iCount.ToString());
                bResult = false;
                //this.pInfoList.Clear();
            }
            finally
            {
                if (pMailDocument != null)
                {
                    Marshal.ReleaseComObject(pMailDocument);
                }

                if (pMailView != null)
                {
                    Marshal.ReleaseComObject(pMailView);
                }

                pMailDocument = null;
                pMailView     = null;
            }

            return(bResult);
        }
Ejemplo n.º 12
0
        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;
            }
        }