I'm trying to trigger an email from Google App script.
const body = HtmlService.createHtmlOutput( "A <b> new task </b> have been added to the Task Manager <br> www.abc.com")
if (props.val == "Jonh"){
MailApp.sendEmail("[email protected]",task,body,{name:"ABC"})
}
The problem is, email body give nothing but just this screen shot
What is the mistake?
CodePudding user response:
In your script, HtmlOutput
object is directly used as the text body. I think that this is the reason for your issue. And, the 3rd argument of sendMail
is the text body. In your situation, I thought that HTML body might be your expcted result. In this case, how about the following modification?
Modified script:
const body = HtmlService.createHtmlOutput("A <b> new task </b> have been added to the Task Manager <br> www.abc.com")
if (props.val == "Jonh") {
MailApp.sendEmail("[email protected]", task, null, { name: "ABC",htmlBody: body.getContent() });
}
Or, in your script, I think that you can directly use the HTML as follows.
if (props.val == "Jonh") {
MailApp.sendEmail("[email protected]", task, null, { name: "ABC",htmlBody: "A <b> new task </b> have been added to the Task Manager <br> www.abc.com" });
}
Or,
const body = HtmlService.createHtmlOutput("A <b> new task </b> have been added to the Task Manager <br> www.abc.com")
if (props.val == "Jonh") {
MailApp.sendEmail({
to: "[email protected]",
subject: task,
htmlBody: body.getContent(),
name: "ABC"
});
}
Or,
if (props.val == "Jonh") {
MailApp.sendEmail({
to: "[email protected]",
subject: task,
htmlBody: "A <b> new task </b> have been added to the Task Manager <br> www.abc.com",
name: "ABC"
});
}