I have a very simple piece of code (just for testing):
import smtplib
import time
server = 'smtp.myprovider.com'
recipients = ['[email protected]']
sender = '[email protected]'
message = 'Subject: [PGS]: Results\n\nBlaBlaBla'
session = smtplib.SMTP(server)
session.sendmail(sender,recipients,message);
This works but the problem is that e-mail clients don't display a sender. I want to be able to add a sender name to the e-mail. Suggestions?
Set up a secure connection using SMTP_SSL() and . starttls() Use Python's built-in smtplib library to send basic emails. Send emails with HTML content and attachments using the email package.
Python provides smtplib module, which defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon. host − This is the host running your SMTP server. You can specify IP address of the host or a domain name like tutorialspoint.com.
To send the mail you use smtpObj to connect to the SMTP server on the local machine. Then use the sendmail method along with the message, the from address, and the destination address as parameters (even though the from and to addresses are within the e-mail itself, these are not always used to route the mail).
smtplib
doesn't automatically include a From:
header, so you have to put one in yourself:
message = 'From: [email protected]\nSubject: [PGS]: Results\n\nBlaBlaBla'
(In fact, smtplib
doesn't include any headers automatically, but just sends the text that you give it as a raw message)
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