Watermark in email sent with MailApp.sendEmail(options) - Possible?

141 views
Skip to first unread message

Alan Wells

unread,
Jun 4, 2019, 8:19:24 AM6/4/19
to Google Apps Script Community
When I try to use position:absolute or position:fixed or position:relative in inline styling of HTML for an email it doesn't work.  Is there any way of placing a transparent element over the content of the email body?  I want to do this in server side code, not client side code.  HTML could be converted to an image in the client side code and the image put into the email, but I don't want to do that.

function test_Send_Email_With_Styling() {
 
var html = '<div style="position:fixed;top:40px;left:60px;background-color: red;opacity:0.5">\
    Watermark Here\
  </div>'
;

  html
= html + '<div>Line One</div>\
    <div>Line Two</div>\
    <div>Line 3</div>\
    <div>Line 4</div>\
    <div>Line 5</div>\
    <div>Line 6</div>\
    <div>Line 7</div>\
    <div>Line 8</div>\
    <div>Line 9</div>'
;
 
 
MailApp.sendEmail({
    to
: "exa...@gmail.com",
    subject
: "Test Watermark",
    htmlBody
: html

 
});
}



Riël Notermans

unread,
Jun 4, 2019, 8:48:32 AM6/4/19
to Google Apps Script Community
Nah,

That is not possible. First because of the limited CSS support of emailclients, and the total different interpretation of it per cliënt.

Images are often blocked as well, and it would create a rather bad experience.



Op di 4 jun. 2019 14:19 schreef Alan Wells <aj.a...@gmail.com>:
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/94d0b2b6-6b0b-4b43-bb93-ee8bc0570808%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Romain Vialard

unread,
Jun 4, 2019, 8:59:10 AM6/4/19
to Google Apps Script Community
Yeah, Gmail has a whitelist of supported CSS properties. Other properties are usually ignored.
Here's the list:

Steve Webster

unread,
Jun 4, 2019, 9:06:08 AM6/4/19
to google-apps-sc...@googlegroups.com
The only other option is Chrome Extension.

Kind Regards,

Steve Webster
SW gApps, President 
Google Product Expert in: Google Apps Script, Drive, and Docs 
Google Vendor (2012-2013) || Google Apps Developer Blog Guest Blogger 
Add-ons: Text gBlaster and Remove Blank Rows


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-script-community.

Alan Wells

unread,
Jun 4, 2019, 10:06:09 AM6/4/19
to Google Apps Script Community
Here is the code that I developed to put a watermark in an email using the background-image, background-repeat: no-repeat;background-position: center;opacity:0.5 inline attributes.  The image use is a publically available YouTube logo that is used in the MailApp example of the Apps Script documentation.


function Send_Email_With_Watermark() {
 
 
var tagOne = '<div style="background-image: url(' +
   
"'https://developers.google.com/youtube/images/YouTube_logo_standard_white.png'" +
     
');background-repeat: no-repeat;background-position: center;opacity:0.5">';
 
var tagEnd = '</div>';
 
 
var content = '<div>Line One</div>\

    <div>Line Two</div>\
    <div>Line 3</div>\
    <div>Line 4</div>\
    <div>Line 5 55555555555555555555555555555555555555555555555555555555555555555555555</div>\

    <div>Line 6</div>\
    <div>Line 7</div>\
    <div>Line 8</div>\
    <div>Line 9</div>'
;

 
var html = tagOne + content + tagEnd;

Alan Wells

unread,
Jun 4, 2019, 12:06:30 PM6/4/19
to Google Apps Script Community
Thank you.  That list was very helpful.  I noticed that "background-image" was supported so decided to pursue that option.
Reply all
Reply to author
Forward
0 new messages