MailApp.sendEmail sending email to myself when not set to in google apps script

与世无争的帅哥 提交于 2020-03-02 07:25:12

问题


MailApp.sendEmail({
to: " someemail@gmail.com , ",
subject: "New change for " + variable1+ " at " + variable2,
htmlBody: "Added: " + addedlist_new.toString() + "<br><br>" + 
"Removed: " + removedlist_old.toString() + "<br><br>" +
" https://docs.google.com/spreadsheets/d/someurlhere ",
})

When I have an email directed to a user other than myself, I find that I end up having the email that was sent to them, in my inbox. It shows it's sent to the user I entered in the "To" area, but it's in my inbox. Why does it place it in my Inbox instead of Sent Mail?


回答1:


Try this way:

var toEmail = "someemail@gmail.com";

var subject = "New change for " + variable1+ " at " + variable2;

var messageBody = "Added: " + addedlist_new.toString() + "<br><br>" + "Removed: " + removedlist_old.toString() + "<br><br>" + "https://docs.google.com/spreadsheets/d/someurlhere";

MailApp.sendEmail(toEmail , subject , "" , {htmlBody: messageBody});



回答2:


I had this problem and found that replacing Mailapp.sendEmail with Gmailapp.sendEmail worked.



来源:https://stackoverflow.com/questions/42139251/mailapp-sendemail-sending-email-to-myself-when-not-set-to-in-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!