Skip to content

Instantly share code, notes, and snippets.

@OOOlledj
Created April 29, 2025 19:58
Show Gist options
  • Select an option

  • Save OOOlledj/28b6ae03ea2d1180a5a9c837c3cb153d to your computer and use it in GitHub Desktop.

Select an option

Save OOOlledj/28b6ae03ea2d1180a5a9c837c3cb153d to your computer and use it in GitHub Desktop.
Python simple SMTP client
import smtplib, traceback
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
email_login = 'test@example.com'
email_password = 'MySecretEmailPassword'
smtp_ssl_server = 'smtp.server.example.com'
recievers = [
"reciever1@example.com",
"reciever2@example.com"
# "reciever3@example.com",
]
msg = MIMEMultipart()
msg['From'] = email_login
message = 'This is a test email'
msg.attach(MIMEText(message, 'html'))
try:
mailserver = smtplib.SMTP_SSL(smtp_ssl_server, 465)
mailserver.set_debuglevel(2)
mailserver.login(email_login, email_password)
for i, mail in enumerate(recievers):
msg['Subject'] = f'SMTP test' {i} - {mail}'
mailserver.sendmail(msg['From'], mail, msg.as_string())
print(f"Successfully send SMTP message to: {mail}")
mailserver.quit()
print('Done, disconnected from SMTP server')
except smtplib.SMTPException:
print('Error sending SMTP message')
print(traceback.format_exc())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment