iT邦幫忙

DAY 19
5

鐵之 Just Do Lotus Notes系列 第 19

使用CSharp透過Domino Server寄送Mail

  • 分享至 

  • xImage
  •  

使用CSharp透過Domino Server寄送Mail(Send Lotus Notes Email Using C#)
今天圍繞的主題還是.NET跟Domino做整合的議題,在Domino使用Notes原生的方式寄信給內部的使用者,這程式技術門檻還比較低改天我們在介紹使用Domino當Mail發信給外部的使用者.

10/06 簽核記錄維護介面(MaintainSignLog)
10/07 群組維護與佈署(Maintain Group & Group Deploy)
10/08 測試郵件範本內容寄送功能-01(MailTemplate)
10/09 用.NET建立COM+元件與Notes做整合
10/10 Lotus Notes Integration with Microsoft _NET Platform (C#)
10/11 用C#取得Notes系統檔案附件(CSharp Get Notes Attachments)
全部精采文章
Domino Server常常被用來作公司其發AP的Mail 發送伺服器,我們就來看看如何使用Csharp來做這樣的整合.
Setp01:執行程式畫面如下,按下「執行任務」

Setp02:觀察Domino Server是否有發送信件

Setp03:查看收件信箱,如以下畫面.

using System;
using System.Windows.Forms;
using Domino;

namespace SendNotesErrorMail
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        static void SendNotesErrorMail(string err, string file)
        {
            //Pass in file name 
            string filename = file;
            //Pass in error message from TryCatch 
            string errMessage = err;           
            string resolution = "派忍犬搜尋中....";
            //Create new notes session 
            NotesSession _notesSession = new NotesSession();
            //Initialize Notes Database to null; nothing in VB. 
            NotesDatabase _notesDataBase = null;
            //Initialize Notes Document to null; nothing in VB. 
            NotesDocument _notesDocument = null;
            //Notes Server Name in form of: ServerName/Domain. 
            string sServerName = "hub/wwcorp";
            string sMailFile = "mail\\dnotes.nsf";
            string password = "";
            string sSendTo = "Doctor Notes/wwcorp";
            string sSubject = "緊急任務執行";
            //required for send, since it's byRef and not byVal, gets set later. 
            object oItemValue = null;
            //use string array to CC Send 
            string[] sCopyTo = new string[4];
            sCopyTo[0] = "卡卡西 <huchungling@gmail.com>";
            //sCopyTo[1] =ConfigurationManager.AppSettings["Recipient1"];
            //sCopyTo[2] =ConfigurationManager.AppSettings["Recipient2"];
            //sCopyTo[3] =ConfigurationManager.AppSettings["Recipient3"];
            //Initialize Notes Session 
            _notesSession.Initialize(password);
            //Get Database via server name & c:\notes\data\mailfilename.nsf 
            //if not found set to false to not create one 
            _notesDataBase = _notesSession.GetDatabase(sServerName, sMailFile,false);
            //If the database is not already open then open it. 
            if (!_notesDataBase.IsOpen)
            {
                _notesDataBase.Open();
            }
            //Create the notes document 
            _notesDocument = _notesDataBase.CreateDocument();
            //Set document type 
            _notesDocument.ReplaceItemValue("Form", "Memo");
            //sent notes memo fields (To: CC: Bcc: Subject etc) 
            _notesDocument.ReplaceItemValue("SendTo", sSendTo);
            _notesDocument.ReplaceItemValue("CopyTo", sCopyTo);
            _notesDocument.ReplaceItemValue("Subject", sSubject);
            //Set the body of the email. This allows you to use the appendtext 
            NotesRichTextItem _richTextItem = _notesDocument.CreateRichTextItem("Body");
            //add lines to memo email body. the \r\n is needed for each new line. 
            _richTextItem.AppendText("Error: " + errMessage + "\r\n");
            _richTextItem.AppendText("File: " + filename + "\r\n");
            _richTextItem.AppendText("Resolution: " + resolution + "\r\n");
            //send email & pass in byRef field, this case SendTo (always have this, 
            //cc or bcc may not always be there. 
            oItemValue = _notesDocument.GetItemValue("SendTo");
            _notesDocument.Send(false, ref oItemValue);
            //release resources. 
            _richTextItem =null;
            _notesDocument =null;
            _notesDataBase =null;
            _notesSession =null;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SendNotesErrorMail("卡卡西的愛書不見了", "這本書叫「親熱天堂」");
        }
    }
}

如需完整程式請在Mail索取.


上一篇
用C#取得Notes系統檔案附件(CSharp Get Notes Attachments)
下一篇
升級到Domino8.5.3控制臺最前面會顯示十六進制字元資訊
系列文
鐵之 Just Do Lotus Notes41
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言