关于c#应用程序调用Notes发送邮件
现在希望实现如下功能,不知道是否可能。
有Notes客户端,有Notes ID,希望应用程序在一定条件下自动通过Notes发出提醒邮件(比如
每星期一提示用户检查上周生产计划完成情况)
备注:应用程序的开发工具为C# --------------------编程问答-------------------- 我也想知道.帮你顶
--------------------编程问答-------------------- 关注 --------------------编程问答-------------------- 找到一个地方有关于调用Lotus Domino Com的,代码是VB的,转换成C#后执行总出现问题。大家也试下,看能解决不
http://www.ibm.com/developerworks/cn/lotus/domino-msnet/ --------------------编程问答-------------------- 又找到一个更详细的关于C#调用的文章,可是好像sServerName的名字输入格式不对,总体是找不到文件。谁知道
NotesSession.GetDatabase(sServerName, sMailFile, false)中sServerName和sMailFile的格式是如何的吗?比如我的Server为server1/SERVER/COMPANY,文件为mail\user1.nsf,因该如何输入呢? sServername = ? sMailFile =?
http://www.notes411.com/dominosource/tips.nsf/0/2114E009A8C8D089802571B6003CD7C4!opendocument --------------------编程问答-------------------- 一下网址提供的方式是可行的,只是到了另外一台机器上运行的时候,提示有COM错误信息。
http://www.notes411.com/dominosource/tips.nsf/0/2114E009A8C8D089802571B6003CD7C4!opendocument
我测试的代码如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace NotesMail
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtFrom;
private System.Windows.Forms.TextBox txtSubject;
private System.Windows.Forms.TextBox txtBody;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtSendTo;
private System.Windows.Forms.Label lblError;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.TextBox txtServer;
private System.Windows.Forms.TextBox txtFile;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.txtSendTo = new System.Windows.Forms.TextBox();
this.txtFrom = new System.Windows.Forms.TextBox();
this.txtSubject = new System.Windows.Forms.TextBox();
this.txtBody = new System.Windows.Forms.TextBox();
this.lblError = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.txtPassword = new System.Windows.Forms.TextBox();
this.txtServer = new System.Windows.Forms.TextBox();
this.txtFile = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// txtSendTo
//
this.txtSendTo.Location = new System.Drawing.Point(117, 32);
this.txtSendTo.Name = "txtSendTo";
this.txtSendTo.Size = new System.Drawing.Size(128, 20);
this.txtSendTo.TabIndex = 0;
this.txtSendTo.Text = "qhzou@szjm.edu.cn";
//
// txtFrom
//
this.txtFrom.Location = new System.Drawing.Point(120, 56);
this.txtFrom.Name = "txtFrom";
this.txtFrom.Size = new System.Drawing.Size(128, 20);
this.txtFrom.TabIndex = 1;
this.txtFrom.Text = "";
//
// txtSubject
//
this.txtSubject.Location = new System.Drawing.Point(120, 88);
this.txtSubject.Name = "txtSubject";
this.txtSubject.Size = new System.Drawing.Size(128, 20);
this.txtSubject.TabIndex = 2;
this.txtSubject.Text = "Test mail";
//
// txtBody
//
this.txtBody.Location = new System.Drawing.Point(120, 112);
this.txtBody.Name = "txtBody";
this.txtBody.Size = new System.Drawing.Size(128, 20);
this.txtBody.TabIndex = 3;
this.txtBody.Text = "No comments";
//
// lblError
//
this.lblError.Location = new System.Drawing.Point(24, 272);
this.lblError.Name = "lblError";
this.lblError.TabIndex = 4;
this.lblError.Text = "Status";
//
// button1
//
this.button1.Location = new System.Drawing.Point(224, 272);
this.button1.Name = "button1";
this.button1.TabIndex = 5;
this.button1.Text = "Send Mail";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(112, 192);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(184, 20);
this.txtPassword.TabIndex = 6;
this.txtPassword.Text = "";
//
// txtServer
//
this.txtServer.Location = new System.Drawing.Point(112, 216);
this.txtServer.Name = "txtServer";
this.txtServer.Size = new System.Drawing.Size(184, 20);
this.txtServer.TabIndex = 8;
this.txtServer.Text = "";
//
// txtFile
//
this.txtFile.Location = new System.Drawing.Point(112, 240);
this.txtFile.Name = "txtFile";
this.txtFile.Size = new System.Drawing.Size(184, 20);
this.txtFile.TabIndex = 9;
this.txtFile.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
this.label1.TabIndex = 10;
this.label1.Text = "Send to";
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 112);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(80, 23);
this.label2.TabIndex = 11;
this.label2.Text = "Body";
//
// label3
//
this.label3.Location = new System.Drawing.Point(24, 88);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(80, 23);
this.label3.TabIndex = 12;
this.label3.Text = "Subject";
//
// label4
//
this.label4.Location = new System.Drawing.Point(24, 56);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(80, 23);
this.label4.TabIndex = 13;
this.label4.Text = "From";
//
// label5
//
this.label5.Location = new System.Drawing.Point(24, 192);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(80, 23);
this.label5.TabIndex = 14;
this.label5.Text = "Notes PW";
//
// label6
//
this.label6.Location = new System.Drawing.Point(24, 216);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(80, 23);
this.label6.TabIndex = 15;
this.label6.Text = "Server";
//
// label7
//
this.label7.Location = new System.Drawing.Point(24, 240);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(80, 23);
this.label7.TabIndex = 16;
this.label7.Text = "File";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(328, 310);
this.Controls.Add(this.label7);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtFile);
this.Controls.Add(this.txtServer);
this.Controls.Add(this.txtPassword);
this.Controls.Add(this.button1);
this.Controls.Add(this.lblError);
this.Controls.Add(this.txtBody);
this.Controls.Add(this.txtSubject);
this.Controls.Add(this.txtFrom);
this.Controls.Add(this.txtSendTo);
this.Name = "Form1";
this.Text = "Send Mail";
this.ResumeLayout(false);
}
#endregion
--------------------编程问答-------------------- o,so long --------------------编程问答-------------------- //一下才为程序的主体部分
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
Boolean bolError = false;
String sErrorMessage = "";
if (this.txtSendTo.Text.Length == 0)
{
bolError = true;
sErrorMessage = "You must fill in the Send To field\n";
}
if (this.txtFrom.Text.Length == 0)
{
bolError = true;
sErrorMessage += "You must fill in the From field\n";
}
if (this.txtSubject.Text.Length == 0)
{
bolError = true;
sErrorMessage += "You must fill in the Subject field\n";
}
if (this.txtBody.Text.Length == 0)
{
bolError = true;
sErrorMessage += "You must fill in the Body field\n";
}
if (bolError)
{
this.lblError.Text = sErrorMessage;
return;
}
else
{
this.lblError.Text = "";
}
try
{
if (SendNotesMail())
{
//Update Status Strip
MessageBox.Show("Email successfully sent!");
}
else
{
//Update Status Strip
MessageBox.Show("Email Not successfully sent!");
}
}
catch (Exception error)
{
Console.WriteLine("{0} My Exception caught.", error);
MessageBox.Show("My Exception caught.\n" + error);
}
finally
{
}
}//end of click
public Boolean SendNotesMail()
{
Domino.NotesSession oNotesSession = null; ;
Domino.NotesDatabase oNotesDatabase = null;
Domino.NotesDocument oNotesDocument = null;
object oItemValue = null;
//String sUserName;
String sPassword = ""; //Password used by COM to pass to the Notes client login.
String sServerName = "";
String sMailFile = "";
oNotesSession = new Domino.NotesSession(); //create a notes session object
sPassword = txtPassword.Text.Trim();
oNotesSession.Initialize(sPassword); //Initialise session by passing a password. Lotus Notes will not load.
try
{
////oNotesSession = new Domino.NotesSession(); //create a notes session object
////sPassword = MsgData.Password;
////oNotesSession.Initialize(sPassword); //Initialise session by passing a password. Lotus Notes will not load.
//sUserName = oNotesSession.UserName;
//Console.WriteLine(sUserName);
//Create a database handle to the database you wish to send the mail message from.
sServerName = txtServer.Text.Trim();
sMailFile = txtFile.Text.Trim();
oNotesDatabase = oNotesSession.GetDatabase(sServerName, sMailFile, false);
//If the database is not already open then open it.
if (!oNotesDatabase.IsOpen)
{
oNotesDatabase.Open();
}
//Create an in memory document in the server database
oNotesDocument = oNotesDatabase.CreateDocument();
//Assign Field Values
oNotesDocument.ReplaceItemValue("Form", "Memo");
oNotesDocument.ReplaceItemValue("From", txtFrom.Text.Trim());
oNotesDocument.ReplaceItemValue("SendTo", txtSendTo.Text.Trim());
oNotesDocument.ReplaceItemValue("Subject", txtSubject.Text.Trim());
oNotesDocument.ReplaceItemValue("Body", txtBody.Text.Trim());
oNotesDocument.SaveMessageOnSend = true; //Ensure memo shows in sent folder
oNotesDocument.ReplaceItemValue("postDate", DateTime.Now.ToShortDateString());
//Send requires an object for the recipients, so I give the send method the SendTo field as an object.
oItemValue = oNotesDocument.GetItemValue("SendTo");
//Send the email
oNotesDocument.Send(false, ref oItemValue);
return true;
}
catch (Exception error)
{
Console.WriteLine("{0} My Exception caught.", error);
return false;
}
finally
{
//if (oNotesSession != null) { Marshal.ReleaseComObject(oNotesSession); }
//if (oNotesDatabase != null) { Marshal.ReleaseComObject(oNotesDatabase); }
//if (oNotesDocument != null) { Marshal.ReleaseComObject(oNotesDocument); }
//if (oItemValue != null) { Marshal.ReleaseComObject(oItemValue); }
oNotesSession = null;
oNotesDatabase = null;
oNotesDocument = null;
oItemValue = null;
GC.Collect();
}
} //end of sendmail
}
}
--------------------编程问答-------------------- 关注! --------------------编程问答-------------------- 的确可以,但是有两个问题需要解决呀:
1). 如果同时发送给几个人,怎么写。如果要抄送怎么些,还有暗送等。
2). 对于oNotesDocument.ReplaceItemValue("Form", "Memo"); 我怎么知道 "Form" 之类的东西可以替代?
望有经验者提个醒
--------------------编程问答-------------------- 有些答案了:
1)发送,抄送,暗送等用数组就可以了。
2)http://www.codeproject.com/vbscript/SendMailLotusNotes.asp?df=100&forumid=253264&exp=0 这个上面有些介绍了。
--------------------编程问答-------------------- oNotesDocument.ReplaceItemValue( "Form ", "Memo ");
oNotesDocument.ReplaceItemValue( "From ", txtFrom.Text.Trim());
oNotesDocument.ReplaceItemValue( "SendTo ", txtSendTo.Text.Trim());
oNotesDocument.ReplaceItemValue( "Subject ", txtSubject.Text.Trim());
oNotesDocument.ReplaceItemValue( "Body ", txtBody.Text.Trim());
oNotesDocument.SaveMessageOnSend = true;
oNotesDocument.ReplaceItemValue( "postDate ", DateTime.Now.ToShortDateString());
//Send requires an object for the recipients, so I give the send method the SendTo field as an object.
oItemValue = oNotesDocument.GetItemValue( "SendTo ");
oNotesDocument.Send(false, ref oItemValue);
return true;
請問各位大蝦﹐如何在內容中插入表格或數據庫報表呢 --------------------编程问答-------------------- 如果只是实现发邮件功能,没有必要非要调用Notes吧,如果Domino启动stmp服务,C#可以通过stmp就可以了吧。
如果Domino没有开STMP服务外那就继续掉用notes吧。
notes提供了可编程的静态库,比较容易实现。 --------------------编程问答-------------------- 如果只是实现发邮件功能,没有必要非要调用Notes吧,如果Domino启动stmp服务,C#可以通过stmp就可以了吧。
如果Domino没有开STMP服务外那就继续掉用notes吧。
notes提供了可编程的静态库,比较容易实现。 --------------------编程问答-------------------- 漂过,我以前也在研究。 --------------------编程问答-------------------- 楼主你还在吗?
我最近也在搞这种东西啊,条件跟你完全一样;你现在搞定了吧?能不能把你的成果贴出来分享啊! --------------------编程问答-------------------- 看了楼主上面的贴子搞定了,谢谢楼主! --------------------编程问答-------------------- 楼主,客户端的密码怎么获取啊,根本找不到啊
补充:企业软件 , Lotus