使用Sendgrid和Google App发送电子邮件

编程入门 行业动态 更新时间:2024-10-21 04:15:51
本文介绍了使用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("api.sendgrid/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("api.sendgrid/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发送电子邮件

本文发布于:2023-11-06 06:39:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1562966.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送电子邮件   Sendgrid   Google   App

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!