Skip to content

Instantly share code, notes, and snippets.

@haloless
Created June 26, 2018 06:54
Show Gist options
  • Select an option

  • Save haloless/ff12a633dfb86918aa8868fead2f7457 to your computer and use it in GitHub Desktop.

Select an option

Save haloless/ff12a633dfb86918aa8868fead2f7457 to your computer and use it in GitHub Desktop.
python for mail server with SSL
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import smtplib
from email.mime.text import MIMEText
from email.header import Header
mail_host="the host"
mail_port = 25
mail_user="the mail"
mail_pass="the pass"
sender = '[email protected]'
receivers = ['[email protected]']
message = MIMEText('Python test email...', 'plain', 'utf-8')
message['From'] = Header("homu", 'utf-8')
message['To'] = Header("hoge", 'utf-8')
subject = 'Python SMTP test'
message['Subject'] = Header(subject, 'utf-8')
try:
# smtpObj = smtplib.SMTP()
smtpObj = smtplib.SMTP_SSL()
smtpObj.connect(mail_host, mail_port)
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
smtpObj.quit()
print "send mail"
except smtplib.SMTPException:
print "Error: failed send mail"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment