javascript - Script to send email to multiple addresses -


i using google sheet send automated pre-filled email whenever fills out required fields in google sheet. how can make following script send different emails based on location user enters? example if user enters london send email email1@email.com or if user enters paris send email email2@email.com. also, need add trigger google sheets know when initiate script?

function fireemail(e){   var username = e.values[1];   var timestamp = e.values[0];   var medaltype1 = e.values[2];   var medaltype2 = e.values[3];   var medalcolor = e.values[4];   var medalrecipient = e.values[5];   var dateneeded = e.values[6];   var medallocation = e.values[7];     var emailbodyhtml = [];   emailbodyhtml += '<b>you have received medal request ' + username + '.</b>';   emailbodyhtml += '<p>onboarding ops medal type, if applicable: ' + medaltype1 + '</p>';   emailbodyhtml += '<p>service ops medal type, if applicable: ' + medaltype2 + '</p>';   emailbodyhtml += '<p>medal color: ' + medalcolor + '</p>';   emailbodyhtml += '<p>medal recipient: ' + medalrecipient + '</p>';   emailbodyhtml += '<p>medal needed by: ' + dateneeded + '</p>';   emailbodyhtml += '<p>please visit <a href="place.com">the medaling document</a> manage request.</p>';    var emailsubject = 'new medal request ' + medallocation + '!';    mailapp.sendemail({     to: "email1@email.com",     name: "medaling request",     subject: emailsubject,       htmlbody: emailbodyhtml       });  } 

to check location can use if-statement (after htlm body)

var mailto; if (medallocation == 'london') { mailto = 'abc@gmail.com'; } else if (medallocation == 'paris' {  mailto = 'def@gmail.com'; }   

if have 2 locations, can use conditional (ternary) operator:

var mailto = (medallocation == 'london') ? 'abc@gmail.com' : 'def@gmail.com' 

if, on other hand have more locations check, advice use of switch statement

var mailto; switch(medallocation) { case 'london':     mailto = 'abc@gmail.com';     break; case 'paris':     mailto = 'def@gmail.com';     break; case 'brussels':     mailto = 'ghi@gmail.com';     break;  default:     mailto = 'jkl@gmail.com'; } 

then, after 'mailto' determined, change mail part to

 mailapp.sendemail({ to: mailto, name: "medaling request", subject: emailsubject htmlbody: emailbodyhtml     

});

the script should have on form submit trigger. hope helps ?


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

python - cx_oracle unable to find Oracle Client -