Python3 implement Send QQ mail function (text) _python

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

This article for everyone to share the PYTHON3 implementation to send QQ Mail function: text, for your reference, the specific content as follows

Note: You need to set up the POP3 and IMAP service and set up a third-party authorization code before using it in QQ.

Then hit x below to fill in the relevant information


Import smtplibfrom email.mime.text import mimetextfrom email.utils import formataddrmy_sender= ' xxxx@qq.com ' # sender email account my _pass = ' xxxxxxx '    # Sender email password (at that time request SMTP password) my_user= ' xxxxxxxx@qq.com '  # Recipient email account, my side sent to myself Rdef Mail (): ret=true Try:  msg=mimetext (' < mail content > ', ' Plain ', ' utf-8 ')  msg[' from ']=formataddr (["xxxxxx", My_sender])   # Corresponding sender's mailbox nickname in parentheses, sender's email account  msg[' to ']=formataddr (["xxxxxxx", My_user])      # corresponding recipient's mailbox nickname in parentheses, Recipient's email account  msg[' Subject ']= ' mail subject '     # The subject of the message, also can be said to be the title  Server=smtplib. Smtp_ssl ("smtp.qq.com", 465)   # SMTP Server in the sender's mailbox, port is 465  server.login (My_sender, My_pass)   # The corresponding in parentheses is the sender's mailbox account, email password  server.sendmail (my_sender,[my_user,],msg.as_string ())    # in parentheses corresponding to the sender's mailbox account, the recipient's mailbox account, Send Message  server.quit () # Close connection except exception:# if the statement in the try is not executed, the following Ret=false  Ret=false return Retret=mail () is executed 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.