I have this function MIME message that I then POST to google draft API. When manually checking in my drafts, the mailContent show's up properly.
const mailContent = req.body.content
.
.
.
var message = 'MIME-Version: 1.0\r\n' +
'Content-type: multipart/alternative; boundary=boundaryboundary\r\n\r\n' +
'--boundaryboundary\r\n' +
'Content-type: text/plain; charset=UTF-8\r\n' +
mailContent + "\r\n\r\n" +
'--boundaryboundary--';
Now I'm trying to add the From, To and Subject fields in my MIME message, and after quite some research, I thought that adding them to the 'body' like so would do the trick:
const mailContent = req.body.content
const from = "exyleprod@gmail.com"
const to = req.body.to || ""
const subject = req.body.subject || ""
.
.
.
var message = 'MIME-Version: 1.0\r\n' +
'Content-type: multipart/alternative; boundary=boundaryboundary\r\n\r\n' +
'From: SomeName ' + '<' + from + '>' + "\r\n" +
'To: ' + '<' + to + '>' + "\r\n" +
'Subject: ' + subject + "\r\n" +
'--boundaryboundary\r\n' +
'Content-type: text/plain; charset=UTF-8\r\n' +
mailContent + "\r\n\r\n" +
'--boundaryboundary--';
But it doesn't... I've tried logging the added fields and they are what I expect. The POST still work's and successfully create's an other draft with the mailContent. However, the 3 fields I'm trying to add don't show up. An I doing this wrong ?
Try to do it this way:
var message = {
from: "sender@example.com",
to: "receiver@example.com",
subject: "Message title",
text: "Plaintext version of the message",
html: "<p>HTML version of the message</p>"
};