在xpages中发送MIME邮件运行时错误时出错
我想从xPages发送电子邮件。我创建了一个测试按钮,添加一个简单的动作“发送邮件”来了,但是当我点击它发送测试电子邮件,我得到这个运行时错误:在xpages中发送MIME邮件运行时错误时出错
Exception
Error sending MIME mail
我试图用这个SSJS电子邮件发送太:
var doc:NotesDocument = database.createDocument();
doc.replaceItemValue("form", "Memo");
doc.replaceItemValue("sendTo", "[email protected]");
doc.replaceItemValue("subject", "hi there!");
doc.replaceItemValue("body", "content here");
doc.send();
,但我得到这个运行时错误:
Error while executing JavaScript action expression Script interpreter error, line=6, col=5: [TypeError] Exception occurred calling method NotesDocument.send() null
我会感谢你的帮助。
谢谢
你试过用下面的代码吗? http://openntf.org/XSnippets.nsf/snippet.xsp?id=create-html-mails-in-ssjs-using-mime
有这样的:
session.setConvertMime(false);
var doc:NotesDocument = database.createDocument();
doc.replaceItemValue("RecNoOutOfOffice", "1"); //no replies from out of office agents
//....
//send the e-mail;
doc.send();
session.setConvertMime(true);
我创建函数来发送邮件像下面的代码:
function sendDocument(memsendto,memcopyto,memsubject,membody,memprincipal) {
var memo:NotesDocument = database.createDocument();
var stream = session.createStream();
var body = memo.createMIMEEntity();
memo.replaceItemValue("Form","Memo");
if(memcopyto!=null) {
memo.replaceItemValue("CopyTo",memcopyto);
}
if(memprincipal!=null) {
memo.replaceItemValue("Principal",memprincipal);
}
memo.replaceItemValue("Subject",memsubject);
memo.replaceItemValue("SendTo",memsendto);
stream.writeText(membody);
body.setContentFromText(stream, "text/html;charset=iso-8859-1",1729)
memo.send();
}
你可以把功能上SSJS脚本Libary并加载它的XPages资源并使用它。希望这个功能可以解决你的问题。
对于那些希望使用它的人来说,OpenNTF Domino API有一个DominoEmail类,旨在使电子邮件的创建更容易。有一个简单的两行版本的一个基本的文本邮件:
DominoEmail myEmail = new DominoEmail();
myEmail.createSimpleEmail("[email protected]", "", "", "Demo Email", "This is a test email from the OpenNTF Domino API", "")
参数为对象toNames,对象ccNames,对象bccNames,弦乐主体,客体的身体,字符串发件人。收件人的对象可以是List,数组或电子邮件地址的逗号分隔字符串。 Body的Object可以是StringBuilder,String或MIMEEntity。
从理论上说,SSJS因为这将是:
var myEmail:org.openntf.domino.email.DominoEmail = new org.openntf.domino.email.DominoEmail();
myEmail.createSimpleEmail("[email protected]", "", "", "Demo Email", "This is a test email from the OpenNTF Domino API", "")
不过,我没有测试过这一点,SSJS的转换为Java类的能力可能有点武断。它可能需要new java.lang.String("[email protected]")
等
请在服务器上检查您的XPages日志文件以获取错误背后的详细信息,并告诉我们。为便于访问日志文件,请使用OpenNTF的XPage日志文件读取器 – 2014-09-21 06:11:56