Names is not getting resolved while using HTML mail in xpages. Is it a problem with the snippet i took from xsnippet or problem with mime itself.
import ss_html_mail;
var mail = new HTMLMail();
var res:java.util.Vector = new java.util.Vector();
res.add("Soundararajan, Thirun");
res.add("Arumugam, Barath");
res.add("Selvam, Abirami")
res.add("Panneerselvam, Saravanan")
mail.setTo(res);
mail.setSubject("HTML Mail");
mail.addHTML("HTML Mail");
mail.send();
However if replace those names with email address or use default SSJS send function it is working. Default send() function resolves the names to email properly
res.add("Soundararajan.Thirun#gmail.com");
res.add("Arumugam.Barath#gmail.com");
res.add("Selvam.Abirami#gmail.com")
res.add("Panneerselvam.Saravanan#gmail.com")
or
var doc = database.createDocument();
var res:java.util.Vector = new java.util.Vector();
res.add("Soundararajan, Thirun");
res.add("Arumugam, Barath");
res.add("Selvam, Abirami")
res.add("Panneerselvam, Saravanan")
doc.replaceItemValue("Form", "Memo");
doc.replaceItemValue("Subject", "An email");
doc.replaceItemValue("SendTo", res);
doc.send();
I use this xsnippet all the time and the problem in your code is that you are using an vector to add the names in. Try to add the names in a Javascript array instead.
Like this
import ss_html_mail;
var mail = new HTMLMail();
var res=[]
res.push("Soundararajan, Thirun");
res.push("Arumugam, Barath");
res.push("Selvam, Abirami")
res.push("Panneerselvam, Saravanan")
mail.setTo(res);
mail.setSubject("HTML Mail");
mail.addHTML("HTML Mail");
mail.send();
Related
When sending an email using nlapiSendEmail() can I specify a email template to use?
I have created an email template in the NetSuite backend. Is there a function I can use to send an email and use that email template?
You can try using nlapiCreateEmailMerger(templateId) to get the body and subject of the email:
var emailMerger = nlapiCreateEmailMerger(templateId);
var mergeResult = emailMerger.merge();
var body = mergeResult.getBody();
var subject = mergeResult.getSubject();
nlapiSendEmail(author, recipient, subject, body, null, null, null, null);
I do mine like this:
var emailSendID='xxxx'; // Email author ID
var emailTempID=123; // Template ID
var emailTemp=nlapiLoadRecord('emailtemplate',emailTempID);
var emailSubj=emailTemp.getFieldValue('subject');
var emailBody=emailTemp.getFieldValue('content');
var renderer=nlapiCreateTemplateRenderer();
renderer.setTemplate(emailSubj);
renderSubj=renderer.renderToString();
renderer.setTemplate(emailBody);
renderBody=renderer.renderToString();
nlapiSendEmail(emailSendID,'noreply#xxxxx',renderSubj,renderBody,finalEmailArray,bccEmailArray);
Previously i am sending a form as a doclink using #functions
Eg: #MailSend("Mary Tsen/";"";"";"Follow this link";"";"";[IncludeDocLink])
Please tell me how to send a mail message that includes a doclink in XPages using Serverside JavaScript.
thank you
The concept of a doclink in a web application don't exist. Therefore you must create an email and include a URL to the specific element. Not sure if using XPINC allows adding of a doclink.
email = database.createDocument();
email.replaceItemValue("Form", "Memo");
email.replaceItemValue("Subject","Test");
email.replaceItemValue("Body","You have email");
email.replaceItemValue("SendTo", sendto);
email.send(false);
In the past what I have done to include a link was to reconstruct the URL, as shown below, for the XPage and add that to the body of the message.
I used a viewPanel link for my scenario, but this should get you down the proper path.
var url:XSPUrl = context.getUrl();
var doc:NotesDocument = row.getDocument();
var unid = doc.getUniversalID();
var scheme = url.getScheme();
var host = url.getHost();
var db = database.getFilePath();
pdfurl = scheme + "://" + host + "/" + db + "/0/" + unid;
You can add a doclink to a rich text item using something like the code below.
var docEmail:NotesDocument = database.createDocument();
var rtitem:NotesRichTextItem = docEmail.createRichTextItem("Body");
docEmail.replaceItemValue("Form", "Memo");
docEmail.replaceItemValue("SendTo", "Your recipient");
docEmail.replaceItemValue("Subject", "Your Subject");
rtitem.appendText("Some text here... ");
rtitem.addNewLine(2);
rtitem.appendText("Click here to view the document => ");
rtitem.appendDocLink(thisdoc, "Some comment text");
rtitem.addNewLine(2);
docEmail.send();
I wired up SendGrid using their documentation as a guide. Nothing fancy here, just want to fire off an email for certain events. Looking at the code below, the SendGrid documentation directs me to use transportWeb.Deliver(message) but this results in "cannot resolve symbol Deliver" However if I use DeliverAsync everything works fine. Just seems sloppy to define a variable that is never used.
SendGridMessage message = new SendGridMessage();
message.AddTo(to);
message.From = new MailAddress(from);
message.Subject = subject;
message.Text = body;
var uid = AppConfigSettings.SendGridUid;
var pw = AppConfigSettings.SendGridPw;
var credentials = new NetworkCredential(uid, pw);
var transportWeb = new Web(credentials);
// transportWeb.Deliver(message); // "Deliver" won't resolve
var result = transportWeb.DeliverAsync(message);
Deliver() was removed in the most recent version of the library. Can you link me to the docs that are out of date?
Is there a way to get the value of the mail file field from the (Company)' Directory ? I wrote a code to get the value but it is not the same in all situation.
Here is the code:
var firstChar = context.getUser().getFullName().charAt(0);
var lastWord = context.getUser().getFullName().split(" ").pop();
var str = firstChar+lastWord;
var str2 = str.slice(0, 8);
var link = "https://server/mail/";
link +=str2+".nsf/iNotes/Mail/?OpenDocument&ui=portal";
return link;
You can access the server directory as any other Notes database. Unless additional address books are there, the user should exist under their username in the "($Users)" view. From there you can retrieve the mail file and server. If it's different from the current server, you may need to check the relevant server document for the hostname.
Borrowing an example from the documentation on the NotesDirectory class and modifying for your purposes, I'd try something like:
var mynotesdir:NotesDirectory = session.getDirectory("server name");
var homeserver = mynotesdir.GetMailInfo("Joe Smith", True);
var mailFileName = homeserver[3];
var link = "https://server/mail/" + mailFileName + "/iNotes/Mail/?OpenDocument&ui=portal";
return link;
The syntax may be wrong, as I copied it from an example and modified it here instead of in Designer, but this should still serve as a good start.....
i'm trying to stream a newly generated pdf (using itext) directly to the body of lotus notes email as an attachment. but i'm getting following error while setting body of the email from bytes
"com.ibm.jscript.types.GeneratedWrapperObject$StaticField incompatible with com.ibm.jscript.types.FBSValue"
following is my completed code(placed in a button of an xpage). Any help would be greatly appreciated
session.setConvertMIME(false);
outputStream:java.io.ByteArrayOutputStream = new java.io.ByteArrayOutputStream();
writePdf(outputStream);
var bytes = outputStream.toByteArray();
var inputStream:java.io.ByteArrayInputStream = new java.io.ByteArrayInputStream(bytes);
var db:NotesDatabase= session.getDatabase("","mail.box")
if (!db.isOpen()) {
print ("No mailbox!")
}
else
{
var doc:NotesDocument=db.createDocument()
doc.replaceItemValue("Form","Memo")
doc.replaceItemValue("From",context.getUser().getCommonName())
doc.replaceItemValue("Principal",context.getUser().getCommonName())
doc.replaceItemValue("SendTo","a#b.com");
doc.replaceItemValue("Recipients","a#b.com");
doc.replaceItemValue("CopyTo","a#b.com");
doc.replaceItemValue("INetFrom","b#c.com");
var strFileName="temp.pdf"
var body:NotesMIMEEntity = doc.createMIMEEntity('Body');
var hdr:NotesMIMEHeader = body.createHeader("Subject");
hdr.setHeaderValAndParams("Subject")
hdr=body.createHeader("MIME-Version")
hdr.setHeaderValAndParams("1.0")
body.setPreamble("multipart message in MIME")
var child1:NotesMIMEEntity= body.createChildEntity()
hdr = child1.createHeader("Content-Disposition")
hdr.setHeaderValAndParams('attachment; filename="test.pdf"')
var stream:NotesStream = session.createStream();
stream.setContents(inputStream)
child1.setContentFromBytes(stream, "application/pdf", body.ENC_IDENTITY_BINARY)
child1.encodeContent(body.ENC_BASE64)
doc.closeMIMEEntities(true,"Body")
doc.save(true, true);
// Restore conversion
session.setConvertMIME(true);
}
function writePdf(outputStream) {
var document:com.itextpdf.text.Document = new com.itextpdf.text.Document();
var writer = com.itextpdf.text.pdf.PdfWriter.getInstance(document,outputStream);
document.open();
document.addTitle("Test PDF");
document.addSubject("Testing email PDF");
document.addKeywords("iText, email");
document.addAuthor("Author");
document.addCreator("Creator");
var passChunk:com.itextpdf.text.Chunk = new com.itextpdf.text.Chunk("Hello");
document.add(new com.itextpdf.text.Paragraph(passChunk));
document.close();
}
you probably would be better off writing a small Java wrapper class.
For starters you need:
var stream:NotesStream = session.createStream();
stream.setContents(inputStream);
stream.setPosition(0);
so the stream is at the beginning.
Update:
Also you have:
var bytes = outputStream.toByteArray();
var inputStream:java.io.ByteArrayInputStream = new java.io.ByteArrayInputStream(bytes);
stream.setContents(inputStream);
where I would write:
var bytes = outputStream.toByteArray();
stream.write(bytes);
Still, make a helper in Java.
Note: iText is GPL licenced. Unless the application you build is internal use only, you either need to buy a commercial license or GPL your code as well. Look at Apache PDFBox for an alternative