Send HTML table in email

1,941 views
Skip to first unread message

Maor Uliel

unread,
Jul 31, 2016, 8:00:43 AM7/31/16
to AdWords Scripts Forum

Hi,

I've wrote this code:
table="<table border=0><tr><th>URL</th><th>Campaign Name</th></tr>";
table
=table+"<tr><td>www.example.com</td><td>Display Campaign</td></tr>";
table
=table+"</table>";

sendEmail
("ma...@example.com", table);

function sendEmail(email, data) {
 
var formattedDate = Utilities.formatDate(new Date(), "GMT+03:00", "dd-MM-yyyy 'at' hh:mm 'GMT+3'");
   
var subject = "Subject - " + formattedDate;
   
Logger.log("Sending email, subject: " + subject);
   
var body = "\n " + data;


 
MailApp.sendEmail(email, '',subject, body);
}


After the mail is sent I get the following code in the mail:
<table border=0><tr><th>URL</th><th>Campaign Name</th></tr><tr><td>www.example.com</td><td>Display Campaign</td></tr></table>

What to do so the table will be as it supposed to be?

Thanks.
Maor 

AussieWeb Conversion

unread,
Aug 1, 2016, 1:10:07 AM8/1/16
to AdWords Scripts Forum
Hi Maor

You need to alter the send email call
Try this:

 MailApp.sendEmail(email, '', subject, {htmlBody: body.join('\n')});

Regards
Nigel

Maor Uliel

unread,
Aug 1, 2016, 1:18:56 AM8/1/16
to AdWords Scripts Forum
Hi,

I've tried it, and it gives me the following error in the logs:
TypeError: Cannot find function join in object

Any more ideas?

Thanks.
Maor

Naman Jindal

unread,
Aug 1, 2016, 2:26:51 AM8/1/16
to AdWords Scripts Forum
Use below code:


table
="<html><body><br><table border=0><tr><th>URL</th><th>Campaign Name</th></tr>";

table
=table+"<tr><td>www.example.com</td><td>Display Campaign</td></tr>";

table
=table+"</table></body></html>";

sendEmail
("ma...@example.com", table);

function sendEmail(email, body) {

  
var formattedDate = Utilities.formatDate(new Date(), "GMT+03:00", "dd-MM-yyyy 'at' hh:mm 'GMT+3'");
    
var subject = "Subject - " + formattedDate;
    
Logger.log("Sending email, subject: " + subject);


  
MailApp.sendEmail(email, subject, '', htmlBody: body });
}

Maor Uliel

unread,
Aug 1, 2016, 2:34:03 AM8/1/16
to AdWords Scripts Forum
Works Great!

Thanks.

Tyler Sidell (AdWords Scripts Team)

unread,
Aug 1, 2016, 9:52:06 AM8/1/16
to AdWords Scripts Forum
Naman and Nigel, thanks for sharing your solutions.

Maor, if you have any further questions feel free to reach out.

Regards,
Tyler Sidell
AdWords Scripts Team

Isiah Mukasa

unread,
Jun 13, 2020, 9:31:17 AM6/13/20
to Google Ads Scripts Forum
How do i put in a variable instead of the url

Google Ads Scripts Forum Advisor

unread,
Jun 14, 2020, 11:35:14 PM6/14/20
to adwords...@googlegroups.com

Hi Isiah,

Could you confirm if what you want is to change the fixed URL on the line of code below and replace it with a variable?


table=table+"<tr><td>www.example.com</td><td>Display Campaign</td></tr>";

If yes, then you may use the modified line of codes below.

var url = 'INSERT_URL_HERE';


  
table="<html><body><br><table border=0><tr><th>URL</th><th>Campaign Name</th></tr>";

table=table+"<tr><td> "+ url +" </td><td>Display Campaign</td></tr>";
table=table+"</table></body></html>


Let me know if you have further questions.

Regards,
Ejay
Google Ads Scripts Team



ref:_00D1U1174p._5004Q20YeXN:ref
Reply all
Reply to author
Forward
0 new messages