如何使用Java来调用Notes API发送邮件(包括附件)
做这个确实是费了老鼻子劲了,搜了半天网上都找不到一个靠谱的教程,最后其实还是看Notes的Info Center 完成的. 做完了看,其实也不是很难, 几个需要注意的地方:
- Import的时候不要用domoin,而要用notes
- 生成附件的时候用RitchText和embedObject. 我就是在这个上浪费了一天时间. ^_^
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | 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(); } } } |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步