0

This the code i am using to send email.

function sendMessage(auth) {
 var gmail =google.gmail('v1');

 var email_lines =[];
 email_lines.push("From:a@gmail.com");
 email_lines.push("To:b@gmail.com");
 email_lines.push('Content-type:text/html;charset=iso-8859-1');
 email_lines.push('MIME-Version:1.0');
 email_lines.push("Subject:Testing ");
 email_lines.push("Hi,");
 email_lines.push("Testing");
 email_lines.push("<b>Hi</b>");

 var email =email_lines.join("\r\n").trim();
 var base64EncodedEmail = new Buffer(email).toString('base64');

base64EncodedEmail=base64EncodedEmail.replace(/\//g,'_').replace(/\+/g,'-');
gmail.users.messages.send({
  auth,
 'userId': 'me',

'resource': {
     'raw': base64EncodedEmail
   }

},function(err, response) {
 if (err) {
   console.log('The API returned an error: ' + err);
   return;
 }
console.log(response);
});
}

i am receiving bounce emails `An error occurred. Your message was not sent.

Hi, Testing Hi Date: Tue, 8 Nov 2016 01:35:08 -0800 Message-Id:`

Please help.

Deepak
  • 37
  • 2
  • 11
  • 1
    You need an extra empty line after the `Subject` before the content of the email: `email_lines.push("Subject:Testing\r\n");` – Tholle Nov 08 '16 at 11:47

1 Answers1

0

@Tholle - This works for me, that extra empty line gives me so much trouble.

I was testing with Javascript, below is my working raw email:

From: xxx@gmail.com
To: xxx@gmail.com
Subject: Test Subject
Reply-To: xxx@gmail.com
Date: Fri Dec 30 2016 09:54:09 GMT-0500 (EST)

Test Body

Some post says Reply-To is required, however I think Date here is not required.