Home >Backend Development >Python Tutorial >Python realizes simple configuration of sending emails

Python realizes simple configuration of sending emails

不言
不言forward
2019-04-01 10:43:442244browse

The content of this article is about the simple configuration of python to send emails. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

This article is implemented using a third-party class library: yagmail; taking QQ mailbox as the sending mailbox as an example.

The final effect: Send an email with specified content to the specified mailbox.

Preparation work

1. Account information for sending emails
For example, the account uses your own qq mailbox, but the 'password' needs to be in the mailbox: Settings - -Account--Enable the POP3/SMTP service. After opening it, you will get an authorization code (just think of it as a 'password'~).

2. Mail server information
You need the address and port of the mail server, which can usually be found in the mailbox help; QQ mailbox is an example, the server address For: smtp.qq.com, the mailbox port is: 465
3, email reach related
, email title, content, recipient, etc. I won’t go into details about these.

How to use

mail = yagmail.SMTP (email account, password, email server address, email server port)
mail.send (recipient list , email subject, email content)

Code example

(Use 1001@qq.com to send emails to 2019@qq.com and 2020@qq.com )

# -*-coding:utf-8-*-import yagmail 
mail = yagmail.SMTP("1001@qq.com","shouquanma","smtp.qq.com",465)
word = "test mail"
mail.send(["2019@qq.com","2020@qq.com"],"python test mail",word)

The function of sending emails is simple to implement~ Of course, send can add more parameters, such as 'attachments', etc. Friends who need it can go online Query and understand~

[Related recommendations: python video tutorial]

The above is the detailed content of Python realizes simple configuration of sending emails. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete