最近在玩domino,积累点经验大家分享一下:
开发notes本来就是摸着石头过河,随时会碰到怪问题,结合上java更辛苦:( 但是notes有一些优点,比如全文检索,安全性,开发时效...所以至今仍然占据群件市场的一席之地.如果能把这些功能通过java调用,也算是废物利用吧:)
例子是发送邮件的,但是得到了session, 其它操作和Notes脚本编程没有什么区别了.
这里的操作例子是我公司的环境. web用户采用IIS的结合NT的认证, 因为NT和domino的账号同步,
因此无需用户再特别登录domino. 发送邮件也采用匿名发送, 在Principal域上标注发件用户,
收到的邮件几乎同Notes发送的没有差别.
操作domino服务器需要抽象类(提供连接操作)和实现逻辑操作的类Sendmail. 分别如下:
===================================================================================
File: Domino.java:
===================================================================================
package steeven.lotus;
import lotus.domino.*;
import java.util.*;
//import lotus.notes.*;
//这个类是抽象类, 其他Java程序扩展此类即可.
/*
环境:
服务器: Domino5.01+NT4
客户端: Windows2000
准备:
打开Notes Administrator修改服务器文档, 按照Help设置DIIOP服务. 其中注意:
安全性:
运行受限制的 Java/Javascript: *
运行无限制的 Java/Javascript: *
仅允许列在通讯录中的用户访问服务器:
否(可匿名)
端口:internet的端口:IIOP: 验证选项:
名称和口令: 是
匿名: 是
2.在domino控制台:
load diiop //启动diiop服务
tell diiop quit //关闭diiop服务
3.连接,可以不用load HTTP服务
推荐使用IOR, C:\Lotus\Domino\Data\domino\html\diiop_ior.txt
copy里面全部内容, 含"IOR:"
s = NotesFactory.createSessionWithIOR(IOR,user,pwd); //用户身份
s = NotesFactory.createSessionWithIOR(IOR); //匿名
3.匿名发送Email时推荐使用“Principal”域,在信箱会正确显示为你的设定值,唯一痕迹是看信时发件人多个Anonymous
From域自动生成为"Anonymous",不可变。
4.调试注意:NotesException不可Cast成Exception否则得不到错误信息
try{
//diiop codes here
}
catch(NotesException e) { //不可Cast
System.out.println(e.getClass().getName()+":"+e.text);
e.printStackTrace();
}
5. 运行环境,需要NOCR.jar,并且需要调用dll, 文件, 设定环境变量Path, 增加c:\lotus\ntoes,
win2000下提示找不到xxxx.dll, 将nxxxx.dll copy后rename即可。
*/
public abstract class Domino {
private final String host="dminoHost";
private final String user="steeven";
private final String pwd="password";
private final String IOR = "IOR:010000002900000049444c3a6c6f7475732f646f6d696e6f2f636f7262612f494f626a6563745365727665723a312e3000000000010000000000000054000000010101000e0000003133332e3232312e3138382e3100acf6310000000438353235363531612d656336382d313036632d656565302d303037653264323233336235004c6f7475734e4f4901000100000000000000";
protected lotus.domino.Session s;
public Domino() throws NotesException{
createSession();
System.out.println("domino:"+s.toString());
}
private void createSession() throws NotesException{
// s = NotesFactory.createSession(host,user,pwd);
// s = NotesFactory.createSessionWithIOR(IOR,user,pwd);
s = NotesFactory.createSessionWithIOR(IOR);
}
}
===================================================================================
File: Sendmail.java:
===================================================================================
package steeven.lotus;
import lotus.domino.*;
import java.util.*;
//import lotus.notes.*;
public class Sendmail extends Domino{
java.util.ArrayList grpUsers = new java.util.ArrayList();
Database db;
Document memo;
RichTextItem rti;
private Vector to = new Vector();
private boolean attachForm = false;
static String mailFooter = "\n\n\n此邮件由WebMail发送 http://www/mail.jsp\n\n";
public Sendmail() throws NotesException{
System.out.println("sendmail");
db = s.getDatabase(null,"WebMail.nsf");
memo = db.createDocument();
rti = memo.createRichTextItem("Body");
memo.setEncryptOnSend(true);
memo.setSignOnSend(true);
memo.sign();
memo.setSaveMessageOnSend(true);
}
public Sendmail(String to,String from,String subject,String body) throws NotesException{
this();
setSendTo(to);
setFrom(from);
setSubject(subject);
setBody(body);
System.out.println("Sendmail with contructor");
}
public Sendmail(String to[],String from,String subject,String body) throws NotesException{
this();
setSendTo(to);
setFrom(from);
setSubject(subject);
setBody(body);
System.out.println("Sendmail with contructor");
}
public void setSubject(String n) throws NotesException{
memo.appendItemValue("Subject",n);
}
public void setFrom(String n) throws NotesException{
memo.appendItemValue("Principal",n);
}
public void setSendTo(String n) throws NotesException{
to.add(n);
memo.appendItemValue("SendTo",n);
}
public void setSendTo(String n[]) throws NotesException{
appendArray("SendTo",n);
for(int i=0;i<n.length;i++)
to.add(n[i]);
}
public void setCopyTo(String n) throws NotesException{
memo.appendItemValue("CopyTo",n);
}
public void setCopyTo(String n[]) throws NotesException{
appendArray("CopyTo",n);
}
public void setAttachForm(String n) throws NotesException{
//如果要attach form
memo.appendItemValue("Form", n);
attachForm = true;
}
public void setAttachFile(String file) throws NotesException{
setAttachFile(file,file);
}
public void setAttachFile(String fileName,String name) throws NotesException{
rti.addNewLine(2);
rti.embedObject(EmbeddedObject.EMBED_ATTACHMENT,null, fileName,name);
}
public void setBody(String n) throws NotesException{
rti.appendText(n);
}
private void appendArray(String field,String[] a) throws NotesException{
for(int i=0;a!=null && i<a.length;i++)
memo.appendItemValue(field,a[i]);
}
public void send() throws NotesException{
rti.appendText(mailFooter);
memo.send(attachForm,to);
System.out.println("mail sent");
}
public static void main(String argv[]){
try{
Sendmail a = new Sendmail("steeven","steeven","来自webmail的测试","text is here");
// a.setAttachFile("\\\\steeven\\vcd\\test.txt");
a.send();
} catch(NotesException e) {
System.out.println(e.getClass().getName()+":"+e.text);
e.printStackTrace();
}
}
}
====================================================================================
Pending Issue:
1. Sendmail还不能发送html邮件. 似乎要自己进行html->rtf的转换. 有办法的朋友可以同我联系
2. 发送文件似乎只能附带domino端的文件.
3. 本人对Java开发很有兴趣, 哪里能提供5位数工资请同我联系. 谢谢.
qq: 7461522(半夜开)
email: phpme@citiz.net(很少看)