0
votes


I want to send emails from xPages. I have created a test button and added a simple action "Send Mail" to it, but when I click on it to send the test email I get this runtime error:

Exception
Error sending MIME mail

I tried to send emails using this SSJS too:

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();

but I got this runtime error:

Error while executing JavaScript action expression Script interpreter error, line=6, col=5: [TypeError] Exception occurred calling method NotesDocument.send() null

I'll appreciate your help.
Thanks

3
Check your XPages log file on the server for the details behind the errors and let us know. For easy access to the log files use XPages Log File Reader from OpenNTFPer Henrik Lausten

3 Answers

0
votes

have you tried using the following code ? http://openntf.org/XSnippets.nsf/snippet.xsp?id=create-html-mails-in-ssjs-using-mime

there is something like:

 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);
0
votes

I have created function to send mail like below code :

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();        
}

You can put that function on SSJS Script Libary and load it on XPAGES resources and use it. Hope that function can solve your problem.

0
votes

For those looking to use it, the OpenNTF Domino API has a DominoEmail class designed to make creation of emails easier. There is a simple two-line version for a basic text email:

DominoEmail myEmail = new DominoEmail();
myEmail.createSimpleEmail("[email protected]", "", "", "Demo Email", "This is a test email from the OpenNTF Domino API", "")

Parameters are Object toNames, Object ccNames, Object bccNames, String Subject, Object body, String sender. The Object for recipients can be a List, an array, or a comma-separated String of email addresses. The Object for the body can be a StringBuilder, a String or a MIMEEntity.

In theory, the SSJS for this would be:

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", "")

However, I've not tested this and SSJS's ability to convert to Java classes can be a bit arbitrary. It may require new java.lang.String("[email protected]") etc