Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting sender's name using gmail api with javascript?

I am sending email using the Gmail APIs. The email is sent correctly, however the From address is not shown as I mentioned "Anup S via TestApp " . Instead it is simply showing the userID/email.

var email_lines = [];
email_lines.push("From: Anup S via TestApp <[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 = btoa(email);
var requestEmail = gapi.client.gmail.users.messages.send({
    'userId': "me", // I also tried changing this - and (obviously) it does not work. 
    'message': {
        'raw': base64EncodedEmail
    }
});

Any ideas on how to fix this?

like image 933
anups Avatar asked Nov 10 '22 05:11

anups


1 Answers

How about trying to add ' mark?

  email_lines.push("From: 'Anup S via TestApp' <[email protected]>");
like image 64
Channy Avatar answered Nov 14 '22 23:11

Channy