Python3 implement Send QQ mail function (attachment) _python

Source: Internet
Author: User
This article is mainly for you to introduce the PYTHON3 implementation of the QQ mail function, accessories, with a certain reference value, Python3 interested in the small partners can refer to

The example of this article for everyone to share the PYTHON3 implementation to send QQ Mail function: Accessories, for your reference, the specific content as follows

Mail attachments can be successfully sent, but the main content of the message cannot be sent, then find out why


Import smtplibfrom email.mime.text import mimetextfrom email.utils import formataddrfrom email.header import Headermy_ Sender = ' xxxx@qq.com ' # sender email account my_pass = ' xxxxx ' # Sender's mailbox password (at that time request smtp password) My_user = ' xxxxxxx@qq.com ' # recipient email account, my side Send To Yourself Rdef mail (): ret = True try:msg = mimetext (open (' a.txt ', ' RB '). Read (), ' base64 ', ' Utf-8 ') msg["Content-type" ] = ' Application/octet-stream ' msg["content-disposition"] = ' attachment; Filename= "A.txt" ' msg[' from ']=formataddr (["xxxxx", My_sender]) # corresponding sender's mailbox nickname in parentheses, Sender's mailbox account msg[' to ']=formataddr (["X XXXXX ", My_user]) # The corresponding recipient's mailbox nickname in parentheses, the recipient's email account msg[' Subject ']= ' mail subject ' # The subject of the message, can also be said to be the title Server=smtplib .    Smtp_ssl ("smtp.qq.com", 465) # The SMTP server in the sender's mailbox, the port is 465 server.login (My_sender, my_pass) # brackets correspond to the sender's mailbox account, email password Server.sendmail (My_sender, [My_user,], msg.as_string ()) # in parentheses corresponds to the sender's mailbox account, recipient's email account, outgoing mail server.quit () # Close Connection Exce PT Exception: # If the statement in the try is not executed, the following ret=false ret = False return is executedRetret = Mail () If Ret:print ("message sent successfully") Else:print ("message sent Failed") 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.