I have been trying to send messages using Google App Script using Gmail Message Send API
Here's the code
var yourEmailAddress = "testingemail@gmail.com";
var myEmailAddress = "senderemail@gmail.com";
var subject = "testing mail";
var forScope = GmailApp.getInboxUnreadCount();
var htmlBody = '<html><body>' + '<h1>HI</h1>' + '</body></html>';
var message = 'MIME-Version: 1.0\r\n' +
'From: Jack Doe <' + myEmailAddress + '>\r\n' +
'To: John Doe <' + yourEmailAddress + '>\r\n' +
'Subject: ' + subject + '\r\n' +
'Content-type: multipart/alternative; boundary=boundaryboundary\r\n\r\n' +
'--boundaryboundary\r\n' +
'Content-type: text/html; charset=UTF-8\r\n' +
'Content-Transfer-Encoding: quoted-printable\r\n\r\n' +
htmlBody + "\r\n\r\n" +
'--boundaryboundary--';
console.log(ScriptApp.getOAuthToken())
var params = {
method: "post",
contentType: "message/rfc822",
headers: {
"Authorization": "Bearer " + ScriptApp.getOAuthToken()
},
muteHttpExceptions: true,
payload: message
};
var resp = UrlFetchApp.fetch("https://gmail.googleapis.com/upload/gmail/v1/users/me/messages/send", params);
Logger.log(resp.getContentText());
The emails are being identified as being dangerous by the recipient's Gmail Client - Gmail identified email to be dangerous
Upon trying to check the email original code, I identified that the email lacks "X-Google-Sender-Auth" which is normally present in emails sent via some Mail Merge tools from Gmail. X-Google-Sender-Auth
How do we add this field when sending the email?