Send email from a Google Script with another 'From' address -
my sheet-bound script sending email using mailapp.sendemail.
the emails sent 'from' own gmail account. project customer, , need email 'from' on these emails.
reading similar questions learn have flexibility in changing name , replyto address, using advanced options of mailapp.sendemail. however, email address still mine , google doesn't offer control on that.
i'm not familiar enough of google services , options find best way this. customer have google apps business, don't.
can somehow create email-sending function standalone script under account, , somehow call project under account? other ideas?
thanks!
emails sent account of user executes script. in case email sent triggered function (installable triggers ones able send emails since requires explicit authorization) email sent account of user created trigger (and authorized it). in case, seems easier solution ask customer execute script himself , initiate triggers himself too. if should not possible indeed use standalone script work kind of proxy, ie receive request send message , send customer account while returning acknowledgement script. that's bit tricky... first solution more elegant.
edit :
i found idea of sending emails through independent script funny gave quick try , seems job pretty easily... test code below (this code should deployed standalone app customer account) :
function doget(e) { logger.log('e = e'+json.stringify(e)); if(e.parameter.recipient==null){return contentservice.createtextoutput("error, wrong request "+json.stringify(e)+"\n\n"+e.parameter.recipient+"\n\n"+e.parameter.subject+"\n\n"+e.parameter.body).setmimetype(contentservice.mimetype.text)}; try{ mailapp.sendemail(e.parameter.recipient, e.parameter.subject, e.parameter.body) }catch(err){ return contentservice.createtextoutput('error : '+err).setmimetype(contentservice.mimetype.text); } return contentservice.createtextoutput('mail sent').setmimetype(contentservice.mimetype.text); }
note : code below goes in spreadsheet script, doget above standalone app running customer account.
function sendmail(recipient,subject,body){ var sent = urlfetchapp.fetch("https://script.google.com/macros/s/---------------s381ko1kqv61e/exec?recipient="+recipient+"&subject="+subject+"&body="+body); logger.log(sent); } function test(){ sendmail('recipient@gmail.com','test message','hello world') }
i able send messages gmail account while being logged different user. (the url above intentionally truncated, don't want send email account ;-)
Comments
Post a Comment