Send an e-mail with Python

Source: Internet
Author: User

First of all to know the use of Python agent login QQ mailbox Email, it is necessary to change their QQ mailbox settings. Here are two things to do: The mailbox opens SMTP function, obtains the authorization Code tutorial link.

After the implementation of the use of Python login QQ email sent QQ Mail, to use to email and smtplib Library

From Email.mime.text import Mimetext to
email.header import header from
smtplib import Smtp_ssl

# QQ Mailbox SMTP Server
host_server = ' smtp.qq.com '
#sender_qq为发件人的qq号码
sender_qq = ' 78**315** '
#pwd为qq邮箱的授权码
pwd = ' i**k**cl**q*b**d '
#发件人的邮箱
sender_qq_mail = ' 78**315** @qq. com '
#收件人邮箱
receiver = ' 13**8 *0**0@qq.com '
#邮件的正文内容
mail_content= ' "Hello, I am a passerby, now in a python login qq email mail test" ""
#邮件标题
Mail _title = ' This is a test email! '

#ssl登录
smtp = Smtp_ssl (host_server)
#set_debuglevel () is used for debugging. A parameter value of 1 indicates that debug mode is turned on, and the parameter value is 0 off debug mode
smtp.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_mail
msg["to" = Receiver
smtp.sendmail (sender_qq_mail, receiver, msg.as_string ())
Smtp.quit ()
Simply change the data such as Host_server, SENDER_QQ, pwd, Sender_qq_mail, receiver, Mail_content, Mail_title, and so on, to achieve a simple send task.

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.