如何使用Java来调用Notes API发送邮件(包括附件)
做这个确实是费了老鼻子劲了,搜了半天网上都找不到一个靠谱的教程,最后其实还是看Notes的Info Center 完成的. 做完了看,其实也不是很难, 几个需要注意的地方:
- Import的时候不要用domoin,而要用notes
- 生成附件的时候用RitchText和embedObject. 我就是在这个上浪费了一天时间. ^_^
package com.ibm.mail; import lotus.notes.*; public class NotesJavaSample implements Runnable { public static void main(String argv[]) { NotesJavaSample t = new NotesJavaSample(); NotesThread nt = new NotesThread((Runnable) t); nt.start(); } public void run() { try { final String mymailserver = "mailserver"; final String mymailfile = "mail6/mymail.nsf"; Session s = Session.newInstance(); String p = s.getPlatform(); System.out.println("Platform = " + p); Registration reg; reg = s.createRegistration(); reg.switchToID ( "C:/notes/data/myid.id", "mypass" ); Database db; db = s.getDatabase(mymailserver, mymailfile); System.out.println("Database title is " + db.getTitle() + " and filepath is " + db.getFilePath()); Document mailmessage; mailmessage = db.createDocument(); mailmessage.replaceItemValue("Form", "Memo"); mailmessage.replaceItemValue("Subject", "Testing the Java interface,how should this work for attach"); mailmessage.replaceItemValue("SendTo", "sendto@gamil.com"); RichTextItem rtitem = mailmessage.createRichTextItem("body"); rtitem.embedObject(EmbeddedObject.EMBED_ATTACHMENT, null, "d:\\notes.txt", "notes.txt"); mailmessage.save(); mailmessage.send("sendto@gmail.com"); } catch (Exception e) { e.printStackTrace(); } } }