Skip to content

Instantly share code, notes, and snippets.

@relthyg
Created January 25, 2022 09:08
Show Gist options
  • Save relthyg/7fd0ffc31f1a54425d16e9efec5929a0 to your computer and use it in GitHub Desktop.
Save relthyg/7fd0ffc31f1a54425d16e9efec5929a0 to your computer and use it in GitHub Desktop.
simple Python script for testing SMTP conenctions
# mail.py
# simple Python script for testing smtp connections
# see https://realpython.com/python-send-email/#sending-a-plain-text-email
import smtplib, ssl
smtp_server = "<your-smtp-hostname>"
smtp_username = "<your-smtp-username>"
sender_email = "<sender-email-address>"
receiver_email = "<receiver-email-address>"
port = 587
password = input("Type your password and press enter: ")
message = """\
From: """+sender_email+"""
To: """+receiver_email+"""
Subject: Hi there
This message is sent from Python."""
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo()
server.starttls(context=context)
server.login(smtp_username, password)
server.sendmail(sender_email, receiver_email, message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment