Beispiel #1
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);
        }
        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();
            }
        }
Beispiel #3
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;
            }
        }