The Python3 programming language is quite versatile and powerful, sending email with Python3 is just as easy and enjoyable of a walk in the programming languages park. If you are using a linux email server, the postfix email program should be configured with the following statement in the main.cf text config file.

On Ubuntu, Debian, Linux Mint (apt packaging variations of the Linux OS)

sudo nano /etc/postfix/main.cf

There should be the following line, or add it to the bottom of the file.

smtputf8_enable = yes

Then, sudo postfix restart (or postfix reload)

Now, Python3 is ready to send Secure UTF8 email.

Here is some |337 code. Please send a comment, perhaps thanks would suffice.

#!/usr/bin/python3
import smtplib
import sys
from email.message import EmailMessage
# =========
# email.py
# =========
# define a variable, e.g.,  EMAIL_LOGIN = 'username@domain_name.us'
# define a variable, e.g.,  EMAIL_PASSWORD = 'password_to_email_server'
with open('/path_to_email_credentials/email.py') as f: exec(f.read())
email = EmailMessage()
SUBJECT = 'This is the subject of the email.'
MESSAGE = 'Some message body of the email, how are you?  Send utf8 or emojies ✅'
email['Subject'] = SUBJECT
email.set_content(MESSAGE)
email['From'] = 'user1@domain_name1'
email['To'] = 'user2@domain_name2'
SMTP_SERVER = 'mail.domain_name.us'
with smtplib.SMTP(SMTP_SERVER, port=587) as secure_send:
    secure_send.ehlo()
    secure_send.starttls()
    secure_send.login(user=EMAIL_LOGIN, password=EMAIL_PASSWORD)
    secure_send.send_message(email)

This will send a utf-8 encoded email via a TLS encrypted email. There is another way to send secure email via SSL, I’ll leave that to a topcoder.cloud reader exercise to do, or please post it in the comments.

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *