Send emails using Sendgrid with google appscript

前端 未结 3 837
别那么骄傲
别那么骄傲 2021-02-06 18:26

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 Appscrip

3条回答
  •  青春惊慌失措
    2021-02-06 18:41

    Try the below code. It worked for me

       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); 
    

    Also ensure that the API key you created in SendGrid has the all the credentials it needs to send the email

提交回复
热议问题