How do you set sender Name and Last name when sending mail via gmail API?
I use this code: https://github.com/chris-brown-nz/python-gmail-api
The code is great and I successfully send mail. However, the name of sender is just the text left from @
sign. example: if John Travis
send email from [email protected]
the name that appears on the receiver side would be johnhomeboy
, instead of John Travis
. What property do I need to set in order to send emails with my name and last name?
message = MIMEText(message_text, 'html') <-- add the 'html' as the second parameter of the MIMEText object constructor.
As mentioned in the comments by AChampion, gmail API accepts standard RFC822 formats so, using Gmail Python APIs sending from a email [email protected]
create_message('[email protected]', 'DESTINATION_EMAIL', 'TITLE', 'BODY')
Sender name can be customised with
create_message("CUSTOMTISED_FROM_TITLE '<[email protected]>'", 'DESTINATION_EMAIL', 'TITLE', 'BODY')
Where create_message
is defined as
def create_message(sender, to, subject, message_text):
"""Create a message for an email.
Args:
sender: Email address of the sender.
to: Email address of the receiver.
subject: The subject of the email message.
message_text: The text of the email message.
Returns:
An object containing a base64url encoded email object.
"""
message = MIMEText(message_text)
message['to'] = to
message['from'] = sender
message['subject'] = subject
return {'raw': base64.urlsafe_b64encode(message.as_string())}
Following the example at https://developers.google.com/gmail/api/guides/sending?authuser=2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With