Guides
Last updated
August 4, 2025

How to Send Email with Python (the Right Way)

Nicolas Rios

Table of Contents:

Get your free
Email Validation
 API key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
START FOR FREE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required

Sending emails automatically is a routine task for many developers — whether it's delivering reports, notifying users, or powering entire marketing campaigns. Fortunately, Python makes this remarkably straightforward thanks to its built-in tools. But while it's easy to fire off emails, doing it correctly — meaning reliably, securely, and professionally — takes one extra step.

Send email with Python - Abstract API

👉 Before you send, it’s crucial to validate each email address. Why? Because sending to invalid or undeliverable addresses can damage your sender reputation, waste resources, and land your messages in the spam folder.

In this guide, you’ll learn how to:

  • Validate email addresses using AbstractAPI's Email Validation API,
  • Send an email using Python’s built-in smtplib, and
  • Combine both steps into a single, polished solution 🚀
Enter your email address to start
Need inspiration? Try
test@abstractapi.com
VALIDATE
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Checking
5
Results for
email
Deliverability:
TEST
Free email:
TEST
Valid format:
TEST
Disposable email:
TEST
Valid SMTP:
TEST
Valid MX record:
TEST
Get free credits, more data, and faster results

Why You Shouldn't Just "Send"⚠️

Let’s start with the problem. Many developers build scripts that send emails directly — without verifying if the address is even real. This might seem harmless at first, but over time, it causes serious issues:

  • High bounce rates: Emails sent to fake or mistyped addresses won’t go through. A high bounce rate signals to providers that you're a spam risk.
  • Wasted resources: Your system spends time and processing power trying to deliver undeliverable messages.
  • Damaged sender reputation: Internet Service Providers (ISPs) track your domain's behavior. Sending to invalid addresses frequently can get you blacklisted.
  • Spam folder trouble: Even your valid recipients may stop seeing your emails because providers begin flagging you.

✅ Best practice: Always verify your email list before sending. And that’s where AbstractAPI steps in.

Steps to validate email with Abstract API

✅ Step 1: Validate Emails with AbstractAPI

Let’s first make sure our emails are legitimate and deliverable. AbstractAPI's Email Validation API gives us real-time feedback on an email address’s status — checking syntax, domain, and even whether the mailbox exists using SMTP checks.

🔌 How it Works

Here’s a Python function that sends a request to AbstractAPI and determines if an email is valid:

import requests

ABSTRACTAPI_KEY = 'your_abstractapi_key_here'

def is_email_valid(email):

    url = f"https://emailvalidation.abstractapi.com/v1/?api_key={ABSTRACTAPI_KEY}&email={email}"

    response = requests.get(url)

    data = response.json()

    # Check if SMTP and deliverability checks passed

    smtp_valid = data.get("is_smtp_valid", "FALSE")

    deliverability = data.get("deliverability", "UNDELIVERABLE")

    return smtp_valid == "TRUE" and deliverability == "DELIVERABLE"

🔍 What This Does

  • Calls AbstractAPI’s validation endpoint with the email you want to check.
  • Parses the response for two key fields:
  • is_smtp_valid: Whether the mailbox exists and accepts messages.
  • deliverability: AbstractAPI’s overall rating based on multiple factors.
  • Returns True only if both indicate the email is likely to be successfully delivered.

🛡️ Why it matters: This tiny check protects your domain, improves deliverability, and keeps your email campaigns clean and effective.

Want to explore more validation capabilities? Check out our full Email Verification Guide.

📤 Step 2: Sending Emails with Python's smtplib

Now that we’ve cleaned up our list, let’s look at how to send an email using Python’s standard libraries.

Python includes two helpful modules for sending emails: smtplib (for sending) and email.message (for formatting). Together, they let you craft and dispatch messages with minimal setup.

✉️ Basic Example:

import smtplib

from email.message import EmailMessage

def send_email(sender, recipient, subject, body, smtp_server, smtp_port, login, password):

    msg = EmailMessage()

    msg["From"] = sender

    msg["To"] = recipient

    msg["Subject"] = subject

    msg.set_content(body)

    # Connect to SMTP server and send the email

    with smtplib.SMTP_SSL(smtp_server, smtp_port) as server:

        server.login(login, password)

        server.send_message(msg)

🛠️ What You’ll Need

  • SMTP credentials: For example, Gmail requires you to enable App Passwords if you use 2FA.
  • Server details: For Gmail, use smtp.gmail.com and port 465 (SSL).
  • Basic message data: From, to, subject, and body.

🧩 Step 3: Put It All Together – Validate & Send

Here’s a complete script that:

  1. Loops through a list of emails.
  2. Validates each one.
  3. Sends only to the verified addresses.

import smtplib

import requests

from email.message import EmailMessage

ABSTRACTAPI_KEY = 'your_abstractapi_key_here'

def is_email_valid(email):

    url = f"https://emailvalidation.abstractapi.com/v1/?api_key={ABSTRACTAPI_KEY}&email={email}"

    response = requests.get(url)

    data = response.json()

    smtp_valid = data.get("is_smtp_valid", "FALSE")

    deliverability = data.get("deliverability", "UNDELIVERABLE")

    return smtp_valid == "TRUE" and deliverability == "DELIVERABLE"

def send_email(sender, recipient, subject, body, smtp_server, smtp_port, login, password):

    msg = EmailMessage()

    msg["From"] = sender

    msg["To"] = recipient

    msg["Subject"] = subject

    msg.set_content(body)

    with smtplib.SMTP_SSL(smtp_server, smtp_port) as server:

        server.login(login, password)

        server.send_message(msg)

# Your email list

email_list = ["valid@example.com", "fake@nowhere.com"]

# Email credentials and message

smtp_server = "smtp.gmail.com"

smtp_port = 465

sender_email = "your_email@gmail.com"

password = "your_app_password"

subject = "Hello from Python!"

body = "This is a test email sent via Python and AbstractAPI 🎉"

# Send to only valid emails

for email in email_list:

    if is_email_valid(email):

        send_email(sender_email, email, subject, body, smtp_server, smtp_port, sender_email, password)

        print(f"✅ Email sent to {email}")

    else:

        print(f"❌ Skipping invalid email: {email}")

🎯 Final Thoughts

Sending emails with Python is simple — but sending them effectively requires a bit more care.

By combining the convenience of Python’s built-in smtplib with the power of AbstractAPI’s Email Validation, you can create a robust, reliable, and professional email system that follows industry best practices.

✨ Validate before you send — and enjoy cleaner lists, fewer bounces, and better results.

🔗 Explore More AbstractAPI Email Tools:

Nicolas Rios

Head of Product at Abstract API

Get your free
Email Validation
key now
See why the best developers build on Abstract
get started for free

Related Articles

Get your free
Email Validation
key now
stars rating
4.8 from 1,863 votes
See why the best developers build on Abstract
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
No credit card required