相关架包下载地址:
http://download.csdn.net/detail/qm4050/5531483
代码如下:
import java.io.File; import lotus.domino.Database; import lotus.domino.Document; import lotus.domino.Item; import lotus.domino.NotesException; import lotus.domino.NotesFactory; import lotus.domino.RichTextItem; import lotus.domino.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class MailPDF { private static final Logger log = LoggerFactory.getLogger(MailPDF.class); private Session session; private Database mailDb; private static MailPDF instance = new MailPDF(); private MailPDF() { } /** * 构造器 * * @param server * Domino Server IP Address or DNS * @param user * who connect to Domino Server * @param password * who's password * @param senderMailFile * the mail file path relatived to <Domino>\Data directory. * @return the class instance. * @throws NotesException */ public static MailPDF create(String server, String user, String password, String senderMailFile) throws NotesException { if (instance.session == null || !instance.session.isValid()) { instance.session = NotesFactory.createSession(server, user, password); } instance.mailDb = instance.session.getDatabase(null, senderMailFile); return instance; } /** * 在特定用户处创建邮件 * * @param sender * 发件人 * @param recipients * 收件人 * @param cc * 抄送 * @param bcc * 密送 * @param body * 正文内容 * @param pdfPath * PDF文件全路径 * @return 是否创建成功 * @throws NotesException */ public boolean createDraftMail(String sender, String[] recipients, String[] cc, String[] bcc, String subject, String[] body, String pdfPath) throws RuntimeException, NotesException { if (session == null || !session.isValid()) { throw new RuntimeException("No Notes Session"); } if (sender == null || "".equals(sender)) { throw new RuntimeException("Sender is Empty"); } if (subject == null) { throw new RuntimeException("Subject is Empty"); } if (mailDb == null) { throw new RuntimeException("Mail Database Open Failed."); } if (!mailDb.isOpen()) mailDb.open(); if (pdfPath == null || "".equals(pdfPath)) { throw new RuntimeException("PDF file Not Found"); } Document doc = mailDb.createDocument(); Item item; doc.replaceItemValue("Form", "Memo"); doc.replaceItemValue("Subject", subject); item = doc.replaceItemValue("EnterSendTo",""); for (String recipient : recipients) { item.appendToTextList(recipient); } if (cc != null) { item = doc.replaceItemValue("EnterCopyTo",""); for (String c : cc) { item.appendToTextList(c); } } if (bcc != null) { item = doc.replaceItemValue("EnterBlindCopyTo",""); for (String bc : bcc) { item.appendToTextList(bc); } } RichTextItem rtItem = doc.createRichTextItem("Body"); if (body != null) { for (String b : body) { rtItem.appendText(b); rtItem.addNewLine(); } } String pdfName = pdfPath.substring(pdfPath.lastIndexOf(File.separator) + File.separator.length()); rtItem.embedObject(1454, "", pdfPath, pdfName); doc.computeWithForm(true, false); doc.save(); return true; } public void close() { try { this.session.recycle(); } catch (NotesException e) { log.error("", e); } } public static void main(String[] args) { try { MailPDF mp = MailPDF.create("localhost", "username", "password", "mail/username.nsf"); mp.createDraftMail("[email protected]", new String[] { "demo/demo", "[email protected]" }, new String[] {"demo/demo", "[email protected]" }, new String[] { "demo/demo", "[email protected]" }, "test", new String[] { "test", "test" }, "D:/test.pdf"); } catch (NotesException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println(e.text); } } }