Send Gmail from Google Sheets using Custom HTML Template

Gmail Automation
Send Gmail from Google Sheets using Custom HTML Template
Jika Merasa Layar Kurang Besar,
Tekan Tombol Ctrl dan + pada Keyboard secara Bersama-sama

Deskripsi [Tampilkan | Sembunyikan]

One of the most commonly asked for Google Apps Script Projects is How to Send custom HTML emails using Apps Script. This lesson will demonstrate how to code in Google Apps Script and create functionality to send custom HTML templated emails to a list of users within your Google Spreadsheet data. Also updating the spreadsheet data.

Source Code [Tampilkan | Sembunyikan]

Source Code Google Apps Script[Tampilkan | Sembunyikan]

 function onOpen() {  
  const ui = SpreadsheetApp.getUi();  
  ui.createMenu('send email').addItem('Approve', 'approver').addToUi()  
 function approver() {  
  const ui = SpreadsheetApp.getUi();  
  const row = SpreadsheetApp.getActiveSheet().getActiveCell().getRow();  
  const data = SpreadsheetApp.getActiveSheet().getRange(row, 1, 1, 3).getValues()[0];  
  const user = {  
   first: data[0]  
   , last: data[1]  
   , email: data[2]  
   , row: row  
  const res = ui.alert('Send to ' + user.first + '(' + + ')?', ui.ButtonSet.YES_NO);  
  if (res == ui.Button.YES) {  
 function sendUser(user) {  
  //let message = '<h1>Hello World</h1>';  
  const temp = HtmlService.createTemplateFromFile('temp');  
  temp.user = user;  
  const message = temp.evaluate().getContent();  
   , subject: 'Tester'  
   , htmlBody: message  
  SpreadsheetApp.getActiveSheet().getRange(user.row, 4).setValue('sent');  

Source Code HTML [Tampilkan | Sembunyikan]

 <!DOCTYPE html>  
   <base target="_top">  
   <p style="font-family: fantasy;color:red;font-size:3em">Hi, <?= user.first ?></p>  
  <div>You have been approved</div>  
  <div> Congrats .... <?= user.first ?> <?= user.last ?></div>  

Review [Tampilkan | Sembunyikan]

- Bisa Kirim Gmail dari Google Sheets
- Tanpa AddOn

- Hanya bisa satu per satu. Tidak bisa langsung banyak.

Contoh File [Tampilkan | Sembunyikan]

No comments

Powered by Blogger.