How to set display name when sending with GMail API?
Asked Answered
C

1

7

With the Gmail API, if you do not provide a FROM header, the FROM header is set to the sender's email address. If I set the FROM header to any of the following forms, Gmail displays a phishing warning to my recipients, stating "Be careful with this message. Gmail could not verify that it actually came from [...]":

name <[email protected]>

'name' <[email protected]>

"name" <[email protected]>

where name is in exactly the same form as my display name.

Is there any way to send my display name without creating the phishing warning?

Campanula answered 23/8, 2020 at 16:36 Comment(1)
I was struggling with this behavior ("error") when I first tried to send an email, even to myself as a test. I found the casing of the from-header matters, https://mcmap.net/q/1487567/-emails-sent-using-gmail-api-are-being-flagged-as-phishy-by-gmail.Vondavonni
D
0

If you are using Java client, you could use

MimeMessage email = new MimeMessage(Session.getDefaultInstance(new Properties(), null));
email.setFrom(new InternetAddress(fromEmailAddress,"displayName"));
email.addRecipient(javax.mail.Message.RecipientType.TO,
                new InternetAddress(toEmailAddress));
email.setSubject(messageSubject);

pass down the displayName to the InternetAddress constructor

Determinate answered 27/7, 2024 at 19:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.