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> /// 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; }
/// <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); }
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(); } }
public bool RelayMailInfo(object pSupervisors, object pSendSecret, string strNotesUID, string strMailContent, object strSender) { bool bResult = false; NotesView pParentView; NotesDocument pParentDocument; try { if (this._strDataBase == "names.nsf") { this.pNotesDatabase = this.pNotesSession.GetDatabase(this._strDomain, this._strDataBase, false); } pParentView = this.pNotesDatabase.GetView("($inbox)"); pParentDocument = pParentView.GetFirstDocument(); while (pParentDocument != null) { if (pParentDocument.UniversalID == strNotesUID) { NotesDocument pRelayDocument = pParentDocument.CreateReplyMessage(false); 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=tcsadmin/OU=技术支持部/OU=产品运营中心/O=runstar"); //pParentDocument.ReplaceItemValue("Principal", strSender); pParentDocument.ReplaceItemValue("Body", ""); pParentDocument.ReplaceItemValue("客服中心", 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 = strSender; //"孙露" pParentDocument.Send(false, ref pSendOwner); bResult = true; break; } else { bResult = false; this.strMessage = "不能找到原始信件,原信件可能已删除,请新建一封信的信件给接收人!"; } pParentDocument = pParentView.GetNextDocument(pParentDocument); } } catch (Exception ex) { this.strMessage = ex.Message; bResult = false; } finally { pParentDocument = null; pParentView = null; } return(bResult); }
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; } }