Created
June 26, 2018 06:54
-
-
Save haloless/ff12a633dfb86918aa8868fead2f7457 to your computer and use it in GitHub Desktop.
python for mail server with SSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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