Home Web Front-end JS Tutorial How to send emails through qq mailbox in python3

How to send emails through qq mailbox in python3

Mar 12, 2018 am 10:09 AM
python3 send Mail

This time I will bring you python3 How to send emails through qq mailbox, what are the precautions for sending emails through qq mailbox in python3, the following is a practical case, let’s take a look one time.

Understand SMTP of qq mailbox

QQ mailbox POP3 and SMTP server address settings are as follows:

Mailbox POP3 server (port 995) SMTP server (port 465 or 587)

qq.com pop.qq.com smtp.qq.com

The SMTP server requires authentication.

1. Turn on the smtp service of qq mailbox

How to turn on the POP3/SMTP/IMAP function?

In order to ensure the security of users' mailboxes, QQ mailboxes are set with POP3/SMTP/IMAP switches. The system default setting is "off". Please "enable" when users need these functions. First, log in to your email and go to Settings - Account;


How to send emails through qq mailbox in python3

Then, in the "Account" settings, find the setting item and set it. As follows:

How to send emails through qq mailbox in python3

Finally, save the settings and open the corresponding service.

2. Code

import smtplibfrom email.mime.text import MIMETextfrom email.utils import formataddr
 
my_sender='XXXXXXX@qq.com'    # 发件人邮箱账号my_pass = 'xxxxxxxxxxxx'              # 发件人邮箱密码(当时申请smtp给的口令)my_user='xxxxxx@xx.com'      # 收件人邮箱账号,我这边发送给自己def mail():
    ret=True
    try:
        msg=MIMEText('填写邮件内容','plain','utf-8')
        msg['From']=formataddr(["发件人昵称",my_sender])  # 括号里的对应发件人邮箱昵称、发件人邮箱账号
        msg['To']=formataddr(["收件人昵称",my_user])              # 括号里的对应收件人邮箱昵称、收件人邮箱账号
        msg['Subject']="邮件主题-测试"                # 邮件的主题,也可以说是标题
 
        server=smtplib.SMTP_SSL("smtp.qq.com", 465)  # 发件人邮箱中的SMTP服务器,端口是465
        server.login(my_sender, my_pass)  # 括号中对应的是发件人邮箱账号、邮箱密码
        server.sendmail(my_sender,[my_user,],msg.as_string())  # 括号中对应的是发件人邮箱账号、收件人邮箱账号、发送邮件
        server.quit()# 关闭连接
    except Exception:# 如果 try 中的语句没有执行,则会执行下面的 ret=False
        ret=False
    return ret
 
ret=mail()if ret:
    print("邮件发送成功")else:
    print("邮件发送失败")
Copy after login

Note: If the recipient address is wrong, the code will still prompt "Email sent successfully". If the address is wrong, you will receive "From qq" in your qq mailbox .com's return letter"

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!

Related reading:

H5 production performance change line chart

What is the difference between python3 and JS

vue2+kendo ui integration

The above is the detailed content of How to send emails through qq mailbox in python3. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the syntax of adding columns in different database systems the same? Is the syntax of adding columns in different database systems the same? Apr 09, 2025 pm 12:51 PM

The syntax for adding columns in different database systems varies greatly, and varies from database to database. For example: MySQL: ALTER TABLE users ADD COLUMN email VARCHAR(255); PostgreSQL: ALTER TABLE users ADD COLUMN email VARCHAR(255) NOT NULL UNIQUE;Oracle: ALTER TABLE users ADD email VARCHAR2(255);SQL Server: ALTER TABLE users ADD email VARCH

What are the Redis memory data types? What are the Redis memory data types? Apr 10, 2025 pm 02:06 PM

Redis provides five core memory data types: String: basic string storage, supporting incremental/decreasing operations. List: Bidirectional linked list, efficient insertion/deletion operation. Set: Unordered set, used for deduplication operations. Hash: Key-value pair storage, suitable for storing structured data. Zset: Ordered set, each element has fractions, and can be sorted by fractions. Choosing the right data type is critical to optimizing performance.

How to simplify email marketing with Composer: DUWA.io's application practices How to simplify email marketing with Composer: DUWA.io's application practices Apr 18, 2025 am 11:27 AM

I'm having a tricky problem when doing a mail marketing campaign: how to efficiently create and send mail in HTML format. The traditional approach is to write code manually and send emails using an SMTP server, but this is not only time consuming, but also error-prone. After trying multiple solutions, I discovered DUWA.io, a simple and easy-to-use RESTAPI that helps me create and send HTML mail quickly. To further simplify the development process, I decided to use Composer to install and manage DUWA.io's PHP library - captaindoe/duwa.

How to monitor debian mail server How to monitor debian mail server Apr 12, 2025 pm 10:06 PM

To ensure that your Debian mail server runs stably, an effective monitoring mechanism is required. This article introduces several monitoring methods, including log checking, monitoring tools and alarm system settings. 1. Log monitoring The log files of the Debian mail server are usually located in the /var/log/ directory, such as /var/log/mail.log. Regularly checking these logs can help you identify potential problems in a timely manner. 2. Monitoring tools and script examples The following provides several Bash script examples for monitoring CPU, memory and disk space usage and sending email alarms: 1. CPU usage monitoring: #!/bin/bashTHRESHOLD=80EMAILS="your_emai

Nginx virtual host configuration skills, efficiently manage multiple websites Nginx virtual host configuration skills, efficiently manage multiple websites Apr 13, 2025 pm 10:03 PM

Nginx virtual host configuration: Playing around your server garden Have you ever thought about how one server elegantly serves multiple websites at the same time? The answer is the Nginx virtual host configuration. This article will take you into Nginx virtual host configuration tips, allowing you to efficiently manage your "server garden" and avoid some common pitfalls. After reading, you will be able to easily configure the virtual host, understand the mechanism behind it, and write efficient and stable Nginx configuration files. Basic preparation: Don't forget that before starting your toolbox, you need to make sure that Nginx is installed and have some understanding of the basic Linux commands and configuration file structure. We won't explain how to install Nginx here, assuming you've completed this step. remember

How Navicat batch modify text data How Navicat batch modify text data Apr 08, 2025 pm 08:27 PM

Navicat provides tips for batch modifying text data: use SQL statements to perform precise modifications through query generators. Simple text replacement with the help of data import/export. Edit data directly in the Data Grid view for small-scale modifications. Common pitfalls of batch modification: SQL injection risk: filtering and escaping user input. Data type mismatch: Make sure the data type matches. Transaction processing: Use transaction processing to ensure data consistency. Error handling: Use the error handling mechanism and record the error message.

What factors need to be considered for SQL deleting rows What factors need to be considered for SQL deleting rows Apr 09, 2025 pm 12:12 PM

When considering deleting SQL lines, you should be aware of the following: Understand how DELETE statements work and do not confuse them with TRUNCATE or DROP. Use the WHERE clause to specify exactly the rows to be deleted to avoid mistaken deletion. Use batch deletion and transactions as needed to improve efficiency and ensure data consistency. Operate with caution, back up data, and use a test environment to avoid data loss.

How to add columns in SQL at the end of a table? How to add columns in SQL at the end of a table? Apr 09, 2025 pm 01:27 PM

Adding columns at the end of a database table is not easy, the specific operation depends on the database system, table size and data volume. Common errors include: ignoring data types, incorrectly using indexes, and concurrent operations. Optimization strategies include: selecting the appropriate storage engine, using partition tables, and utilizing database replication technology. Good code readability and maintainability also help avoid problems. Only by operating with caution and paying attention to the underlying mechanism can we avoid risks in data security and integrity.

See all articles