5👍
✅
Use email.utils.make_msgid
to create RFC 2822-compliant Message-ID header:
msg-id = [CFWS] "<" id-left "@" id-right ">" [CFWS]
5👍
I found the above answer to be incredibly confusing. Hopefully the below helps others:
import smtplib
import email.message
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
import email.utils as utils
def send_html_email(subject, msg_text,
toaddrs=['foo@gmail.com']):
fromaddr = 'me@mydomain.com'
msg = "\r\n".join([
"From: " + fromaddr,
"To: " + ",".join(toaddrs),
"Subject: " + subject,
"",
msg_text
])
msg = email.message.Message()
msg['message-id'] = utils.make_msgid(domain='mydomain.com')
msg['Subject'] = subject
msg['From'] = fromaddr
msg['To'] = ",".join(toaddrs)
msg.add_header('Content-Type', 'text/html')
msg.set_payload(msg_text)
username = fromaddr
password = 'MyGreatPassword'
server = smtplib.SMTP('mail.mydomain.com',25)
#server.ehlo() <- not required for my domain.
server.starttls()
server.login(username, password)
server.sendmail(fromaddr, toaddrs, msg.as_string())
server.quit()
- Django rest framework – PrimaryKeyRelatedField
- Can i access the response context of a view tested without the test client?
- Where is Pip3 Installing Modules?
- Cannot Log in to Django Admin Interface with Heroku Deployed App
- How to check that an uploaded file is a valid Image in Django
Source:stackexchange.com