使用Sendgrid和Google App发送电子邮件 [英] Send emails using Sendgrid with google appscript
本文介绍了使用Sendgrid和Google App发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个googlesheet插件来发送邮件。对于发送邮件,我正在使用sendgrid。
我找不到用于使用Google Appscript发送邮件的任何文档或示例代码。这是我正在使用的代码,但是效果不好。
I am creating a googlesheet addon to send mails.And for sending mails I am using sendgrid. I cannot find any documentation or example code for sending mails with Google Appscript. This is the code I am using, but it is no good.
var data = {
"api_user":"username",
"api_key":"ioioi",
"to":[],
"tonnage":[],
"cc":[],
"ccname":[],
"bcc":[],
"subject":sub,
"from":from,
"html":htmlBody
}
var headers = { "Accept":"application/json",
"Content-Type":"application/json"
};
data = JSON.stringify(data);
var options = {
"method": "POST",
"payload": data,
"headers": headers,
"muteHttpExceptions": true
};
var res = UrlFetchApp.fetch("https://api.sendgrid.com/api/mail.send.json", options);
是否有人有想法或代码使用googl应用程序通过sendgrid发送电子邮件?
Does anyone have any idea or code to send emails with sendgrid using googl appscript?
推荐答案
尝试以下代码。
var SENDGRID_KEY ='Your API KEY';
var headers = {
"Authorization" : "Bearer "+SENDGRID_KEY,
"Content-Type": "application/json"
}
var body =
{
"personalizations": [
{
"to": [
{
"email": "email id of the sender"
}
],
"subject": "Hello, World!"
}
],
"from": {
"email": "From email id"
},
"content": [
{
"type": "text",
"value": "Hello, World!"
}
]
}
var options = {
'method':'post',
'headers':headers,
'payload':JSON.stringify(body)
}
var response = UrlFetchApp.fetch("https://api.sendgrid.com/v3/mail/send",options);
Logger.log(response);
还请确保您在SendGrid中创建的API密钥具有发送电子邮件所需的所有凭据
Also ensure that the API key you created in SendGrid has the all the credentials it needs to send the email
这篇关于使用Sendgrid和Google App发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文