I am trying to send email with below code.
import smtplib
from email.mime.text import MIMEText
sender = 'sender@sender.com'
def mail_me(cont, receiver):
msg = MIMEText(cont, 'html')
recipients = ",".join(receiver)
msg['Subject'] = 'Test-email'
msg['From'] = "XYZ ABC"
msg['To'] = recipients
# Send the message via our own SMTP server.
try:
s = smtplib.SMTP('localhost')
s.sendmail(sender, receiver, msg.as_string())
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
finally:
s.quit()
cont = """\
<html>
<head></head>
<body>
<p>Hi!<br>
How are you?<br>
Here is the <a href="http://www.google.com">link</a> you wanted.
</p>
</body>
</html>
"""
mail_me(cont,['xyz@xyzcom'])
I want "XYZ ABC" to appear as the sender's name when the email is received and its email address as 'sender@sender.com'. but when i receive email i am receiving weird details in "from" fields of the email message.
[![from: XYZ@<machine-hostname-appearing-here>
reply-to: XYZ@<machine-hostname-appearing-here>,
ABC@<machine-hostname-appearing-here>][1]][1]
I have attached a screenshot of the email that i receive.
how can i fix this according to my need.