SoFunction
Updated on 2024-10-29

Complete steps for python to automatically send QQ mailboxes

I. Authorization code acquisition

Turn it on:

Send a text message:

Click I've Sent after sending:

Copy this authorization code and save it for next time.

II. Transmission of texts and annexes

You just need to change the email address, authorization code, and of course add the attachment path if you want to send attachments.

python code:

# coding=gbk
"""
Author : Chuan Chuan
@time : 2021/11/10 10:50
Group : 970353786
"""
import smtplib
from  import MIMEText
from  import MIMEImage
from  import MIMEMultipart
from  import MIMEApplication

# Written as a generic function interface, just uncomment the arguments if you want to use it directly
def send_email(msg_from, passwd, msg_to, text_content, file_path=None):
    msg = MIMEMultipart()
    subject = "python implementation of mailboxes to send emails"  # Theme
    text = MIMEText(text_content)
    (text)

    # file_path = r'' # If you need to add an attachment, give the path
    if file_path:  # The first function parameter is set to None by default, if you want to add attachments, you can change it yourself.
        docFile = file_path
        docApart = MIMEApplication(open(docFile, 'rb').read())
        docApart.add_header('Content-Disposition', 'attachment', filename=docFile)
        (docApart)
        print('Send attachment!')
    msg['Subject'] = subject
    msg['From'] = msg_from
    msg['To'] = msg_to
    try:
        s = smtplib.SMTP_SSL("", 465)
        (msg_from, passwd)
        (msg_from, msg_to, msg.as_string())
        print("Sent successfully.")
    except  as e:
        print("Failed to send.")
    finally:
        ()
msg_from = '283****79@'  # Sender's e-mail
passwd = 'd******a'  # Fill in the authorization code for the sender's email (the one you just got)
msg_to = '283******9@'  # Recipient's e-mail, I send it to myself #
text_content = "hi,this is a demo!" # Content of messages sent
file_path = '' # Directory of attachments to be sent
send_email(msg_from,passwd,msg_to,text_content,file_path)

Run: (e-mail received)

III. Continued upgrading

Could you build on this, for example by crawling the main content of a certain web page and sending it to an email address? There are tons of interesting things about crawling! For example, I auto-fill my body temperature, and send the result of the filling to my email.

Python code: (txt inside for my specifics)

# coding=gbk
"""
Author : Chuan Chuan
@time : 2021/11/10 11:50
Group : 970353786
"""
import smtplib
from  import MIMEText
from  import MIMEMultipart
from  import MIMEApplication

def send_email(msg_from, passwd, msg_to, text_content):
    msg = MIMEMultipart()
    subject = "Automated computerized temperature results."  # Theme
    text = MIMEText(text_content)
    (text)

    msg['Subject'] = subject
    msg['From'] = msg_from
    msg['To'] = msg_to
    try:
        s = smtplib.SMTP_SSL("", 465)
        (msg_from, passwd)
        (msg_from, msg_to, msg.as_string())
        print("Sent successfully.")
    except  as e:
        print("Failed to send.")
    finally:
        ()
msg_from = '28****579@'  # Sender's e-mail
passwd = 'dw****rodhda'  # Fill in the authorization code for the sender's email (the one you just got)
msg_to = '2****9579@'  # Recipient Email

with open("log_t.txt", "r",encoding="utf-8") as f:  # Open the file
    data = ()  # Read the file
    text_content = data # Content of messages sent
    send_email(msg_from,passwd,msg_to,text_content)  

Running effects:

IV. Declarations

Automated e-mail delivery is for personal study and practice only. If you use it for any other purpose, you are responsible for the consequences and will not be held liable.

This article on python automatically send QQ mailbox is introduced to this, more related python automatically send QQ mailbox content please search for my previous articles or continue to browse the following related articles I hope you will support me more in the future!