Log In

Step 1

Please make sure that you have imported necessary modules being used in this Python script.

Step 2

Please change the following in this script:

  • sender@example.com: the sender’s email address.
  • recipient@example.com: the recipient’s email address.
  • USERNAME: your SMTP2GO username.
  • PASSWORD: your SMTP2GO password.
#!/usr/bin/python

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

username = 'USERNAME'
password = 'PASSWORD'
msg = MIMEMultipart('mixed')

sender = 'sender@example.com'
recipient = 'recipient@example.com'

msg['Subject'] = 'Your Subject'
msg['From'] = sender
msg['To'] = recipient

text_message = MIMEText('It is a text message.', 'plain')
html_message = MIMEText('It is a html message.', 'html')
msg.attach(text_message)
msg.attach(html_message)

mailServer = smtplib.SMTP('mail.smtp2go.com', 2525) # 8025, 587 and 25 can also be used.
mailServer.ehlo()
mailServer.starttls()
mailServer.ehlo()
mailServer.login(username, password)
mailServer.sendmail(sender, recipient, msg.as_string())
mailServer.close()

Ready for better email delivery?

Try SMTP2GO free for as long as you like:

Try SMTP2GO Free → Paid plans available for over 1,000 emails/month.