How to use Python to log on to your mailbox and send emails

Source: Internet
Author: User
This is really a black technology. The original advertising emails were generated in this way. Good guys send holiday cards and send commemorative emails to their girlfriends. bad guys learn to post advertisements and spam emails. I hope you can learn something interesting and meaningful. This is really a black technology. The original advertising emails were generated in this way. Good guys send holiday cards and send commemorative emails to their girlfriends. bad guys learn to post advertisements and spam emails. I hope you can learn something interesting and meaningful.

Today, I will show you how to implement the Simple Mail function. We need to use the email and smtplib libraries to implement the environment python3.5.

First of all, you need to know that you need to change your QQ mailbox settings when logging on to the QQ mailbox using a python proxy. Here, you need to do two things: enable the SMTP function in the mailbox and obtain the authorization code tutorial link.

Then let's take a look at how to change the template code and use Python to log on to the QQ mailbox and send QQ emails.

We will first attach the simplest code

First of all, you need to know that you need to change your QQ mailbox settings when logging on to the QQ mailbox using a python proxy. Here, you need to do two things: enable the SMTP function in the mailbox and obtain the authorization code.

From email. mime. text import MIMETextfrom email. header import Headerfrom smtplib import SMTP_SSL # qqmail smtp server host_server = 'smtp .qq.com '# sender_qq is the sender's QQ number sender_qq = '2017 ***' # pwd is the authorization code pwd = '* * iao *** lxpic *** '# sender's email address: sender_qq_mail = '2017 *** @ qq.com' # recipient's email address: 'Thunder *** @ gmail.com '# Email body content mail_content = 'Hello, I am from Zhihu [xxx]. now I am conducting a test of logging on to the QQ mailbox and sending emails using python '# Mail title mail_title = 'XXX' # ssl logon to smtp = SMTP_SSL (host_server) # set_debuglevel () is used for debugging. If the parameter value is 1, the debug mode is enabled. if the parameter value is 0, the debug mode smtp is disabled. set_debuglevel (1) smtp. ehlo (host_server) smtp. login (sender_qq, pwd) msg = MIMEText (mail_content, "plain", 'utf-8') msg ["Subject"] = Header (mail_title, 'utf-8 ') msg ["From"] = sender_qq_mailmsg ["To"] = receiversmtp. sendmail (sender_qq_mail, receiver, msg. as_string () smtp. quit ()

You can simply send tasks by changing data such as host_server, sender_qq, pwd, sender_qq_mail, receiver, mail_content, and mail_title.

The preceding figure shows how to use Python to log on to your mailbox and send email details. For more information, see other related articles in the first PHP community!

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.