Last active
December 27, 2015 08:48
-
-
Save noexpect/7298623 to your computer and use it in GitHub Desktop.
pythonでGmail経由でメール送信。
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
| import smtplib | |
| from email.mime.text import MIMEText | |
| class sendGmail: | |
| username, password = '[email protected]', 'password' | |
| def __init__(self, to, sub, body): | |
| host, port = 'smtp.gmail.com', 465 | |
| msg = MIMEText(body) | |
| msg['Subject'] = sub | |
| msg['From'] = self.username | |
| msg['To'] = to | |
| smtp = smtplib.SMTP_SSL(host, port) | |
| smtp.ehlo() | |
| smtp.login(self.username, self.password) | |
| smtp.mail(self.username) | |
| smtp.rcpt(to) | |
| smtp.data(msg.as_string()) | |
| smtp.quit() | |
| if __name__ == '__main__': | |
| to = '[email protected]' | |
| sub = 'python smtplib' | |
| body = 'hello world' | |
| sendGmail(to, sub, body) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
冗長だったし、拡張する予定ないのでコンストラクタに処理突っ込んだ