zoukankan      html  css  js  c++  java
  • 如何使用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();
    		}
    	}
    }
  • 相关阅读:
    setTimeout()和setInterval()的区别
    iOS开发小技巧
    iOS应用跳转到App Store评分
    前端小技巧-定位的活学活用之仿淘宝列表
    前端CSS
    用c# 开发html5的尝试,试用bridge.net
    Faster数据库研习,一
    五一劳动节,讲讲NEO智能合约的调试
    NEO GUI 多方签名使用
    NEO智能合约开发(二)再续不可能的任务
  • 原文地址:https://www.cnblogs.com/db2zos/p/2328639.html
Copyright © 2011-2022 走看看