Forked from binderclip/python-smtp-send-qq-mail.py
Created
February 17, 2016 07:35
-
-
Save youqingkui/0cdea9820182c554cf0d to your computer and use it in GitHub Desktop.
用 Python 发送 QQ 邮箱的邮件
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 getpass import getpass | |
| def prompt(prompt): | |
| return input(prompt).strip() | |
| fromaddr = prompt("From: ") | |
| toaddrs = prompt("To: ").split() | |
| subject = prompt("Subject: ") | |
| print("Enter message, end with ^D (Unix) or ^Z (Windows):") | |
| # Add the From: To: and Subject: headers at the start! | |
| msg = ("From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" | |
| % (fromaddr, ", ".join(toaddrs), subject)) | |
| while True: | |
| try: | |
| line = input() | |
| except EOFError: | |
| break | |
| if not line: | |
| break | |
| msg = msg + line | |
| print("Message length is", len(msg)) | |
| server = smtplib.SMTP_SSL('smtp.qq.com') | |
| server.set_debuglevel(1) | |
| print("--- Need Authentication ---") | |
| username = prompt("Username: ") | |
| password = getpass("Password: ") | |
| server.login(username, password) | |
| server.sendmail(fromaddr, toaddrs, msg) | |
| server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment