Backend Development 7 min read

Automating Email Sending with Python SMTP: Text, HTML, and Attachments

This tutorial demonstrates how to use Python's SMTP libraries to programmatically send plain‑text, HTML, and attachment emails, covering SMTP basics, service activation, configuration steps, and complete code examples for each email type.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Automating Email Sending with Python SMTP: Text, HTML, and Attachments

In automated testing, test results are often emailed; this guide shows how to use Python to send emails via SMTP, covering plain‑text, HTML, and attachment messages.

It explains the Simple Mail Transfer Protocol (SMTP), its role in reliable email transmission, and the steps to enable SMTP service in QQ mail, including generating a 16‑digit authorization code.

Code snippets illustrate setting up the mail server, sender address, authorization code, and recipient list, then composing messages using email.mime.text.MIMEText for plain‑text and HTML content.

Examples include sending a simple text email, an HTML email with a hyperlink, and an email with a non‑image attachment, showing how to use email.mime.multipart.MIMEMultipart , email.mime.base.MIMEBase , and email.header.Header to attach files and encode them properly.

The article concludes by reminding readers to enable SMTP, generate the required authorization code, and test the script, encouraging feedback and further improvements.

PythonAutomationEmailSMTPMIME
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.