I am amazed at the extent to which the lotus script libraries are mimicked in the Server Side Javascript libraries in XPages . The following is a simple illustration of a scenario that amazed me --- sending mails with rich text tables from an XPage.
Copy and paste the following code fragment into a XPage button control, preview the same on the Browser or Notes Client and you are ready to go.
Ensure that you give your own mail address so that you can check the functionality
/*******************************************************/
//change the mail address to test it for your self
var mailAddress="ozinisle.inferno@blogspot.com";
var currDB: NotesDatabase=session.getCurrentDatabase();
var mailDoc:NotesDocument=currDB.createDocument();
var bodyRt:NotesRichTextItem=mailDoc.createRichTextItem("Body");
var RTELEM_TYPE_TABLECELL =7;
mailDoc.replaceItemValue("Form","Memo");
mailDoc.replaceItemValue("SendTo",mailAddress);
mailDoc.replaceItemValue("Subject","XPage Mail");
bodyRt.appendTable(3,4);
bodyRt.update();
var bodyRtNav:NotesRichTextNavigator=bodyRt.createNavigator();
if (bodyRtNav.findFirstElement(RTELEM_TYPE_TABLECELL)) {
bodyRt.beginInsert(bodyRtNav);
bodyRt.appendText("hi this is my value");
bodyRt.endInsert();
} else {
getComponent("errs").setValue('no table found');
}
try {
if (bodyRtNav.findNextElement(RTELEM_TYPE_TABLECELL)) {
bodyRt.beginInsert(bodyRtNav);
bodyRt.appendText("hi this is my other value");
bodyRt.endInsert();
}
} catch (exp) {
getComponent("errs").setValue(getComponent("errs").getValue()+ @NewLine()+'no table found 2');
}
bodyRt.update();
mailDoc.send();
/*******************************************************/
Hope this helps :)
How to attach more than one files into mail document...
ReplyDelete@Syed: take a look into the following post - http://ozinisle.blogspot.com/2010/06/add-multiple-attachments-to-rich-text.html
ReplyDeleteWhen i use these codes(posted by you for sending mails), i am getting below error:
ReplyDeleteException
Error while executing JavaScript action expression
Script interpreter error, line=36, col=9: Exception occurred calling method NotesDocument.send() null
@Nice : The code seems to work fine for me....
ReplyDeleteI did a little test and it is send out mails with out any issues....
Can you plz elaborate on how you worked with the code
Thanks a lot
ReplyDeletehappy to share :)
ReplyDeleteHow do I embed fields from my xpage into the email? I have fields like employee name and department in on my page.
ReplyDeleteWhen i use these codes(posted by you for sending mails), i am getting below error:
ReplyDeleteException
Error while executing JavaScript action expression
Script interpreter error, line=36, col=9: Exception occurred calling method NotesDocument.send() null
Hi Aboobacker,
ReplyDeleteGuess you have reused the code as such. 'Nice' had reported the same issue and I guess he did the same.
I have mentioned the sendTo address as "mailAddress". Try changing that to your email address
Hope that helps
Dear Sir ,
ReplyDeleteI have same problem like Nice & Aboobacker (Script interpreter error, line=36, col=9: Exception occurred calling method NotesDocument.send() null)
How to fix this problem ?
post your code. Let me analyse it before answering
ReplyDeleteDear Karthikeyan :
ReplyDeleteI solved my Problem.
Your sample Code is perfect, problem is Server name,my Server name include underscore char , casuse this problem.very thanks for your help.
Jeffrey wu.
nice to know. Thanks for sharing the same
ReplyDeleteHi Karthikeyan, the error occured because, Mail sending from web browser was restricted at server level.
ReplyDeleteInteresting. Never tried such server level restriction before. Will look into it and modify the sample with error handlers if time permits :) Thanks a lot for sharing the same
ReplyDelete