使用 JavaScript 自动化客户端 Lotus Mail






2.56/5 (8投票s)
通过 Lotus Notes 发送邮件,使用 JavaScript。

引言
奉以真主之名,我开始撰写本文档。一些程序员已经编写过文章,介绍如何在 Windows 应用程序中自动化 Lotus Notes(通过 Lotus Notes 发送电子邮件)。但是,当我们需要在客户端通过 Lotus Notes 发送电子邮件时,我们可以选择使用 Java 脚本。
此 JavaScript 直接自动化客户端 Lotus 客户端。基本思路是获取客户端 Lotus 数据库,并将您的邮件注入到邮件数据库中。我在这里不会写得更多。但脚本会完成这项工作。
实现
以下是我列出的通过 Lotus Notes 发送电子邮件的脚本。首先,我们需要为 Lotus.NotesSession
创建 ActivexObject,然后我们需要使用该对象的的方法来发送邮件。ActiveX 对象可以有多种方法来自动化 Lotus Notes。我们需要创建一个邮件文档对象来创建邮件主题和内容。
JavaScript代码
function SendScriptMail(mToMail,mSub,mMsg)
{
var Maildb;
var UserName;
var MailDbName;
var MailDoc;
var AttachME;
var Session;
var EmbedObj;
var server;
try
{
// Create the Activex object for NotesSession
Session = new ActiveXObject('Notes.NotesSession');
if(Session !=null)
{
// Get the user name to retrieve database
UserName = Session.UserName;
// Retrieve database from username
MailDbName = UserName.substring(0,1) + UerName.substring(
UserName.indexOf( " " ,1) + 1 ,UserName.length) + ".nsf"
// Get database
Maildb = Session.GetDatabase("", MailDbName);
// open the database
if(Maildb.IsOpen != true)
{
Maildb.OPENMAIL();
}
// Create the mail document
MailDoc = Maildb.CREATEDOCUMENT();
// From email id (Username)
MailDoc.Form = 'Memo';
// To email id
MailDoc.sendto = mToMail;
// Subject of the mail
MailDoc.Subject = mSub;
// Content of the mail
MailDoc.Body = mMsg
// if you want to save message on send, give true here
MailDoc.SAVEMESSAGEONSEND = false;
// send the mail (check ensure the internet connection)
MailDoc.Send(true);
// save the mail in draft (no need of internet connection)
MailDoc.Save(false, true);
// destroy the objects
Maildb = null;
MailDoc = null;
AttachME = null;
EmbedObj = null;
Session.Close();
Session = null;
alert('Mail sent successfully');
}
else
{
alert('Mail not sent');
}
}
catch(err)
{
if(err == '[object Error]')
{
alert('Error while sending mail,
Please check Lotus Notes installed in your system');
}
else
{
alert('Error while sending mail');
}
}
}
使用限制
重要提示:出于安全原因,Internet Explorer 不允许脚本在客户端创建 ActivexObject。因此,脚本将无法工作。为了避免这种情况,我们需要更改 Internet 安全设置,从工具菜单中转到“Internet 选项”,然后转到“安全”选项卡,选择“本地 intranet”或“internet”,单击“自定义级别”按钮,然后将打开安全设置对话框,选择“初始化并脚本未标记为可脚本化的 ActiveX 控件”,选择“启用”或“提示”选项。更改此设置后,您将失去在互联网上的安全性。因此,最好在“受信任的站点”中更改相同的设置,并将您的页面添加到“受信任的站点”中。