I am trying to use Mail.App to send an email with an html body, and combining it with the option to change the "from" name and "replyTo" email address.
My current script is:
MailApp.sendEmail (emailAddress, emailSubject, htmlBody, {htmlBody: htmlBody});
I believe I should add {from: "name", replyTo: "replies#test.com"}. I end up with:
MailApp.sendEmail (emailAddress, emailSubject, htmlBody, {htmlBody: htmlBody}, {from: "name", replyTo: "replies#test.com"});
But it gave me an error. What am I doing wrong?
There should only be one options object in there, like this:
MailApp.sendEmail(emailAddress, emailSubject, htmlBody,
{ htmlBody: htmlBody, name: 'Tuyen Nguyen', replyTo: 'replies#test.com' });
MailApp expects the third parameter in the first line there to be a plain text version of the email you are sending. In the event the recipient's email program does not support HTML email for some reason, it will show the plain text version instead.
You are using the htmlBody variable for both the plain text version and the HTML version of the email message. That technically works, but be aware that some recipients may see HTML tags in their email messages.
See MailApp.sendEmail().
Just try:
MailApp.sendEmail({
to: "recipient#example.com",
subject: "Logos",
htmlBody: "inline Google Logo<img src='cid:googleLogo'> images! <br>" +
"inline YouTube Logo <img src='cid:youtubeLogo'>});
}
from this example: https://developers.google.com/apps-script/reference/mail/mail-app#sendEmail(Object)
Check the link you can add any of the options into the object
Related
Referring to this thread I'm able to retrieve my signature from Gmail with the code var signature = Gmail.Users.Settings.SendAs.list("me").sendAs.filter(function(account){if(account.isDefault){return true}})[0].signature;
But if I attach the retrieved HTML to the email body, the recipient see the raw code instead of my signature.
I red many threads with this problem, but I'm unable to understand how fix this, I'm not expert with HTML.
Please could someone help me?
GmailApp allows you to parse html using htmlBody:
var signature = Gmail.Users.Settings.SendAs.list("me").sendAs.filter(function(account){if(account.isDefault){return true}})[0].signature;
GmailApp.sendEmail("email#gmaiil.com", "signature test", "test", {htmlBody: signature})
Update:
The signature of GmailApp.sendEmail is:
sendEmail(recipient, subject, body, options)
or:
sendEmail(recipient, subject, body)
In your case, you need to use option 1.
replyTo is specified using the options object.
So, to summarize, here is your code:
mia_firma = '<p>' + corpo + '</p>' + mia_firma; // concat htmlBody
MailApp.sendEmail(dest, // recipient email - string
sogg, // should be subject - string
corpo, // mail body - WILL BE IGNORED if you use htmlBody
{ // options - object
htmlBody: mia_firma,
replyTo: "reply_to#XYZ.page"
}
);
You can see the full documentation here
When I run the program, only boss1#gmail.com gets bcc'ed.
I've debugged the program and each variable is logged correctly.
MailApp.sendEmail(
EPEmail,
"Internship Opportunity at "+OP,
emailText,{
cc:Manager1,
cc:EPManager2,
cc:EPManager3,
bcc:Boss,
bcc:"boss1#gmail.com"}
);
Requirement:
Send emails with multiple cc / bcc addresses.
Solution:
From the "Advanced parameters" section of sendEmail documentation:
a comma-separated list of email addresses to CC
This means we can concatenate the variables and separate them with commas using the + operator to achieve your goal.
Example:
MailApp.sendEmail(
EPEmail,
"Internship Opportunity at "+OP,
emailText,{
cc:Manager1+','+EPManager2+','+EPManager3,
bcc:Boss+','+"boss1#gmail.com"}
);
Reference:
sendEmail(recipient, subject, body, options)
function myFunction(){
// html email
var htmlEmailBody = HtmlService.createTemplateFromFile('html-template-name');
// email title
var subject = "sample title..";
// this must be set or .sendEmail will not work. You can insert your own email address to get a copy of the email or just let it blank. Alternative you can delete bcc and just the emailAddress value to send 1 email only.
var emailAddress = "";
// same like emailAddress this must be set aswell. You can just keep it blank and use htmlBody for your html email. Alternative delete htmlBody and use normalBody for plain text email instead.
var normalBody = "";
MailApp.sendEmail(emailAddress, subject, normalBody, {
name: "Your Name",
htmlBody: htmlEmailBody.evaluate().getContent(),
bcc: 'sample1#gmail.com,sample2#web.de'
});
}
BCC tag is not visible in email details (even while checking original message) although the mail are being sent to bcc email addresses. CC tag is working fine
MailApp.sendEmail({
to: '123#jhb.hv',
cc: 'test#test.com',
bcc: 'test1#test.com, test2#test.com, test3#test.com',
name : 'Test',
subject: "New request",
htmlBody: "<p>Test</p>"
this is the code being used.
I am using google scripts to send text messages. I would like to use the newline character to format messages properly. I would expect the code below to display:
Hello.
How are you?
Instead, the following is displayed:
Hello.How are you?
var response = "Hello.\nHow are you?"
MailApp.sendEmail(recipient, subject, response);
Please note recipient is in the format:
"(956) xxx-xxxx" <1740xxxxxxx.1956xxxxxxx.dhJVMRb1ZG#txt.voice.google.com>
That is, this is being sent as sms via gmail.
UPDATE, I tried:
function myFunction()
{
GmailApp.sendEmail(
'(956) xxx-xxxx <1262xxxxxxx.1956xxxxxxx.7ljPdnVXKg#txt.voice.google.com>',
'test mailApp', 'test3', { htmlBody: "break3<br />line"});
}
and the result was:
test3
which tells me that any email sent to txt.voice.google.com is processed as text only, not html. I hope there's some workaround.
jimpudar's answer wont work!
The text of email will be "Hello.How are you?"
Instead use this:
GmailApp.sendEmail("me#gmail.com", "Email", "This won't be displayed", { htmlBody:
"Hello</br>How are you?"
}
);
Or you can do:
var recipient = "example#gmail.com";
var subject = "This email";
var body = "Hello.</br>How are you?";
GmailApp.sendEmail(recipient, subject, "This won't be displayed",{htmlBody:
body
}
);
Both will work ;)
As you maybe noticed, you can use any html code inside the {htmlBody: whatever}
Good luck, and have fun with scripting :)
I am not 100% sure on this, but I seem to remember using HTML tags to accomplish this.
var response = "Hello.<br>How are you?";
This probably won't work if your email is being sent as text. It worked for me when sending the text as an HTML email.
I have a script that sends an email to the person who submitted a form to me. However, I would like to send the email from an "anonymous" account so the confirmation email doesn't come from my account. Is there a way to send it from a different account so it doesn't look like I am manually generating all these emails. Thanks!
My script is something like the following:
if (user = email) {
GmailApp.sendEmail(user, subject, message);
}
Where 'user' is the google account of the person submitting and 'email' is the email address the person submitting wishes to have the confirmation sent to.
Again, is there a way to make the GmailApp.sendEmail(from:'Anonymous') ???
Well, I can't answer fully that it can be anonymous. You could author the app with a "dummy" account to obscure your email address, but if you're on a business or education account that won't really work. Also, you can put a little bit of smoke to distract the recipient by giving the email an "alias" name.
MailApp.sendEmail(userEmail,
"Help Desk Ticket",
"Thanks for submitting your issue. \n\nWe'll start " +
"working on it as soon as possible. \n\nHelp Desk",
{name:"Help Desk"});
}
The most important part of that is the element in the last line {name:"Help Desk}. This makes your email "name" Help Desk, but you can still see the sending email address if you mouse over it (which is why I recommended a "dummy" email address in the beginning).
You can see the context of the script in this tutorial: https://developers.google.com/apps-script/articles/helpdesk_tutorial
Here is an example of how I used the same thing in a script:
function mailCheatSheet(copyId,userEmail,mrNumber){
var copyId = copyId;
var userEmail = userEmail;
var mrNum = mrNumber;
// Convert temporary document to PDF by using the getAs blob conversion
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
var subject = "SA Funding request by: "+userEmail;
var body = userEmail +" has submitted a SA Funding Inquiry for " +mrNumber +", which is attached to this email. \n"
+"Please ensure there are no errors before printing. \n"
+"If there are errors, please notify: xyz#abc.com. \n\n";
MailApp.sendEmail(userEmail, subject, body, {name: 'SA Worksheet Helperbot', htmlBody: body, attachments: pdf});
// Delete temp file
DocsList.getFileById(copyId).setTrashed(true);
}
If you just want to make it look like you're not sitting around all day typing out email responses to things (I'd assume so your boss thinks you're doing something useful), then you could add the alias name to your GmailApp method AND add a disclaimer line at the bottom of the email body like this:
var body = userEmail +" has submitted a SA Funding Inquiry for " +mrNumber +", which is attached to this email. \n"
+"Please ensure there are no errors before printing."
+"\n\nThis email was automatically authored by Form Helperbot. If there is an error, please report it to: dummyEmail#xyz.com"
MailApp.sendEmail(userEmail, subject, body,{name: 'Form Helperbot',htmlBody: body, attachments: pdf});
If you want to send from an anonymous account only because you don't want to receive the replies, it might be a better idea to specify a dummy reply-to address in your email notifications.
MailApp.sendEmail(userEmail, subject, body, {name: 'SA Worksheet Helperbot', htmlBody: body, attachments: pdf, replyTo: donotreply#example.com});