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);
Related
I am able to send a mail by using send grid API how to send a mail in particular format by using send grid
Mail-Format
please find the Mail-format image
Pass in the body as HTML and set the IsBodyHtml = true. I do this using SendGrid.
public Task SendEmailAsync(string email, string subject, string htmlMessage)
{
var client = new SmtpClient(host, port)
{
Credentials = new NetworkCredential(userName, password),
EnableSsl = false
};
return client.SendMailAsync(
new MailMessage(from, email, subject, htmlMessage) { IsBodyHtml = true }
);
}
I am using firebase functions to send users a notification. I can user string interpolation like so:
const original = change.after.val();
const lover = context.auth.uid;
const recipient_username = original.username;
const topic = `${recipient_username}_notifications`;
But now I need to make a database call to get the username from the user_id, and use the username to get the value of loves form the 'original' snapshot, but this does not work:
return db.ref('/users/' + lover).once('value', (snapshot) => {
var username = snapshot.val().username;
var love = original.loves.username // I need this to use the variable username, but it is just saying "username"
console.log("lover username")
console.log(username)
console.log("loves")
console.log(loves)
const payload = {
notification:{
title: "You've got Love!",
body: `${username} sent you Love! Refresh your inbox to recieve it, and why not send some back!`
}
};
How can I change var love = original.loves.username to be something like: var love = original.loves.${username}?
The database looks like this:
users/
username: usernamehere
love/
otherusername: 10 // the amount of love they sent.
You have called .val() on the original turning this into a Javascript object.
Traversing paths in Javascript objects can be done with the .loves helper functions or using string lookups. Try the following
var username = snapshot.val().username;
var love = original.loves[username];
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'm trying to send an email using SendGrid with Azure Mobile Services. I'm using the sample code here for reference:
http://azure.microsoft.com/en-us/documentation/articles/store-sendgrid-nodejs-how-to-send-email/
exports.post = function(request, response) {
var SendGrid = require('sendgrid');
var toEmail = 'myemail#mydomain.com';
var mail = new SendGrid.Email({
to: toEmail,
from: toEmail,
subject: 'Hello SendGrid',
text: 'This is a sample email message.'
});
var sender = new SendGrid('my_user','my_ key');
};
I'm getting an TypeError creating the sender. The Email object is created as expected. I'm not sure what I'm doing wrong. From looking at the code in sendgrid.js, the exports look correct. Any ideas?
Here is the error:
Error in script '/api/my_api.js'. TypeError: object is not a function
Note:
I have added sendgrid using npm
From sendgrid.js
var Sendgrid = function(api_user, api_key, options) {
}
module.exports = Sendgrid;
Per the github docs:
var sendGrid = require('sendgrid')('my_user', 'my_key');
var mail = new sendGrid.Email({
to: toEmail,
from: toEmail,
subject: 'Hello SendGrid',
text: 'This is a sample email message.'
});
https://github.com/sendgrid/sendgrid-nodejs
sendgrid.Email is a method of the object returned by instantiating the module. To access sendgrid.Email, you must call the function returned by requiring SendGrid.
Your code should look as follows:
exports.post = function(request, response) {
var sendgrid = require('sendgrid');
var sender = new sendgrid('my_user','my_ key');
var toEmail = 'myemail#mydomain.com';
var mail = new sender.Email({
to: toEmail,
from: toEmail,
subject: 'Hello SendGrid',
text: 'This is a sample email message.'
});
};
Edit: Corrected method names.
The SendGrid package was not being imported correctly. I was thrown off the error because the Email object was being created correctly.
I rechecked my package.json and updated the project with npm install. Everything started working.
Some of the answers above helped me, but I still had to figure this out.
Here is what I did to fix the object is not a function error when using sendgrid. This is obviously, version specific, so you may have to adjust the version number depending on the version of sendgrid you are using.
Add sendgrid as a dependency in the package.json file of your azure mobile services project.
"dependencies": {
"sendgrid": "^1.9.2"
},
"devDependencies": {
"sendgrid": "^1.9.2"
},
The instructions at https://github.com/sendgrid/sendgrid-nodejs clearly state this, but somehow, I overlooked it.
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();