Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save youqingkui/0cdea9820182c554cf0d to your computer and use it in GitHub Desktop.

Select an option

Save youqingkui/0cdea9820182c554cf0d to your computer and use it in GitHub Desktop.

Revisions

  1. @binderclip binderclip revised this gist Aug 4, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion python-smtp-send-qq-mail.py
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,9 @@ def prompt(prompt):
    print("Message length is", len(msg))

    server = smtplib.SMTP_SSL('smtp.qq.com')
    server.set_debuglevel(1)
    # 如果是其他的服务,只需要更改 host 为对应地址,port 对对应端口即可
    # server = smtplib.SMTP_SSL(host='smtp.qq.com', port=465)
    server.set_debuglevel(1) # 开启调试,会打印调试信息
    print("--- Need Authentication ---")
    username = prompt("Username: ")
    password = getpass("Password: ")
  2. @binderclip binderclip created this gist Aug 4, 2015.
    33 changes: 33 additions & 0 deletions python-smtp-send-qq-mail.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    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()