简体   繁体   中英

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 <username@gmail.com>");
email_lines.push("To: to_user@gmail.com");
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?

如何添加'标记?

  email_lines.push("From: 'Anup S via TestApp' <username@gmail.com>");

The From email address has to match the email address of the logged in user for the API, it can't be someone else. Is that true in your case? If that is true then you should be able to set whatever display name on the email you want, ie:

email_lines.push("From: \\"Some Name Here\\" <myEmailAddr@gmail.com>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM