Python3 sends emails via QQ mail and python3 sends emails

Source: Internet
Author: User
Tags email account

Python3 sends emails via QQ mail and python3 sends emails
Python3 send emails via QQ mail 0. Learn about SMTP in QQ mail

Set POP3 and SMTP server addresses in QQ mail as follows:

Email POP3 server (Port 995) SMTP server (Port 465 or 587)
Qq.com Pop.qq.com Smtp.qq.com

The SMTP server requires authentication.

1. How can I enable POP3, smtp, and IMAP functions for the SMTP service of QQ mail?

To ensure the security of your mailbox, the POP3/SMTP/IMAP switch is set for QQ mailbox. The default setting is "off". enable these functions when you need them ". First, log on to the mailbox and go to settings-account;

Then, in "Account" Settings, find the settings and set them as follows:

Finally, save the settings to enable the corresponding service.

2. Code
Import smtplibfrom email. mime. text import MIMETextfrom email. utils import formataddrmy_sender = 'xxxxxxx @ qq.com '# sender's email account my_pass = 'xxxxxxxxxxxxxx' # sender's email password (the password for smtp application at that time) to_user = 'xxxxxx @ xx.com '# the recipient's email account. I am sending my own def mail (): ret = True try: msg = MIMEText ('fill in the mail content ', 'plain ', 'utf-8') msg ['from'] = formataddr (["sender nickname", my_sender]) # corresponding sender's email nickname in brackets, Sender's email account msg ['to'] = formataddr (["recipient's nickname", to_user]) # The corresponding recipient's email nickname and recipient's email account msg ['subobject'] = "Email Subject-test" # the Subject of the email, which can also be said to be the title server = smtplib. SMTP_SSL ("smtp.qq.com", 465) # SMTP server in the sender's email address, Port: 465 server. login (my_sender, my_pass) # The brackets indicate the sender's email account and password server. sendmail (my_sender, [to_user,], msg. as_string () # It corresponds to the sender's email account, recipient's email account, and email sending server. quit () # Close the connection except T Exception as e: # If the statement in try is not executed, the following ret = False will be executed
Print (e) ret = False return retret = mail () if ret: print ("email sent successfully") else: print ("email failed ")

 

Note: If the recipient address is incorrect, the Code still prompts "email sent successfully". If it is an address error, you will receive a "Bounce Message from qq.com" in the QQ mailbox"

 

From: https://www.cnblogs.com/xshan/p/7954317.html if any offense, please contact me.

This article is for reference only and cannot be used for commercial purposes.

Related Article

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.