13

I'm trying to send an email through Google API.

I'm using googleapis for Google API access in node.js .

My issue is that when I try to send a simple mail with no attachments, I get the following error:

'raw' RFC822 payload message string or uploading message via /upload/* URL required

I didn't define in my request that there is an attachment and I don't see any error in the email addresses.

Please help.

My code:

    var google = require('googleapis');
    var gmailClass = google.gmail('v1');

    var email_lines = [];

    email_lines.push("From: \"Some Name Here\" <[email protected]>");
    email_lines.push("To: [email protected]");
    email_lines.push('Content-type: text/html;charset=iso-8859-1');
    email_lines.push('MIME-Version: 1.0');
    email_lines.push("Subject: New future subject here");
    email_lines.push("");
    email_lines.push("And the body text goes here");
    email_lines.push("<b>And the bold text goes here</b>");

    var email =email_lines.join("\r\n").trim();

    var base64EncodedEmail = new Buffer(email).toString('base64');

    gmailClass.users.messages.send({
        auth: OAuth2Client,
        userId: "me",
        message: 
        {
             raw: base64EncodedEmail
        }           
      },
    function(err, results){});
5
  • Did you try making base64EncodedEmail url-safe? Example: base64EncodedEmail.replace(/\+/g, '-').replace(/\//g, '_') Commented Aug 8, 2014 at 16:05
  • @mscdex it did change parts in the string but I still got the same error Commented Aug 8, 2014 at 16:29
  • I have the same issue. The API seams to be responding the same no matter what I send. Commented Aug 23, 2014 at 22:46
  • I even tried sending back a raw message that I received as a response from the API itself. I got the same error message. Commented Aug 23, 2014 at 22:50
  • Related: stackoverflow.com/questions/34546142/… Commented Jan 10, 2017 at 16:35

1 Answer 1

13

Changes were made to version 1.0.3 of the google api. Try using the following syntax:

gmailClass.users.messages.send({
    auth: OAuth2Client,
    userId: "me",
    resource: 
    {
         raw: base64EncodedEmail
    }           
  }

Make sure that base64EncodedEmail is url safe. You can use the base64EncodedEmail.replace(/\+/g, '-').replace(/\//g, '_') code posted by mscdex. This syntax worked for v. 1.0.11

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for posting! Was wondering why some of my code stopped working. Where did you find out about this API update? I ask because even Google's documentation still has it listed as message, not resource as of 10-21-14: developers.google.com/gmail/api/v1/reference/users/messages/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.