SoFunction
Updated on 2024-11-10

Python one line of code to achieve automatic e-mail function

1. Use Python to send daily dog licking greetings to goddesses

Automate the most basic emails with Python (Subject + Recipient)

point of knowledge (math.)

Mail Structure

Take 263 Enterprise Mail as an example

E-mail form element
most fundamental To + Subject
most common To + Subject +main body (of a book)
General Process Application Mail To+Subject+Body+Carbon Copy (for email)
Sending report emails To + Subject + Cc +attachment (email)
Add statement mailings To+Subject+Body+Copy+Attachment

Python calls to zmail module

import zmail
('danzhao@','password').send_mail('danzhao@',{'subject':'I'm your lickspittle #1.'})

Change the recipient to a goddess.

import zmail
('danzhao@','password').send_mail([('Goddess','danzhao@')],{'subject':'I'm your lickspittle #1.'})

Homework:Change the recipient's eponym to Captain America.

Problems that may be encountered

Confirm that the password is correct, but still says that the password is not right: may need to open the corresponding SMTP special password (authorization code), such as QQ mailboxes

Server not responding

Some special emails may need to set up smtp server by themselves, generally go to the mailbox provider, take 263 enterprise mail as an example.

This time you need to write the following code

import zmail
('danzhao@','password',smtp_host='smtp.',smtp_port=25).send_mail('danzhao@',{'subject':'I'm your lickspittle #1.'})

Extended Knowledge:api

For example, the dog licking quotes API:/api/

import requests
import json
import zmail
response = ('/api/')
tiangou = ()['content']
('danzhao@','password').send_mail('danzhao@',{'subject':tiangou})

2. Python for the Daily Podcast

Automate the most commonly used emails with Python (Subject + To + Body + Cc)

import zmail
mail = dict(
	subject='Today's data situation',
	content_text='100 new business cards entered today, 50 added effectively, add rate is 50%'
)
('danzhao@','password').send_mail('danzhao@',mail)

On this basis, the focus is on the rate of addition.

Text with formatting

import zmail
mail = dict(
	subject='Today's data situation',
	content_html='100 new business cards entered today, 50 added effectively, adding rate of <strong>50%</strong>'
)
('danzhao@','password').send_mail('danzhao@',mail)

Note: Additional HTML basics are required.

When there are many recipients

import zmail
mail = dict(
	subject='Today's data situation',
	content_text='100 new business cards entered today, 50 added effectively, add rate is 50%'
)
('danzhao@','password').send_mail(['yupinze@','danzhao@'],mail)

I might have to copy the boss.

import zmail
mail = dict(
	subject='Today's data situation',
	content_text='100 new business cards entered today, 50 added effectively, add rate is 50%'
)
('danzhao@','password').send_mail('danzhao@',mail,cc='chenxiaomei@')

Homework: Change the copyist's alias to Tien Shan Da Li.

3. Sending daily reports in Python

Automate the most commonly used emails with Python (Subject+Recipient+Body+Attachment)

import zmail
mail = dict(
	subject='Today's data situation',
	content_text='100 new business cards entered today, 50 added, 50% add rate. Please see the attachment for details of each group.',
	attachments=r'E:\Onedrive\Desktop\Statements.xlsx'
)
('danzhao@','password').send_mail('danzhao@',mail)

If there is more than one attachment, the code is as follows

import zmail
mail = dict(
	subject='Today's data situation',
	content_text='100 new business cards entered today, 50 added, 50% add rate. For details of each group, please refer to the attached statement 2.',
	attachments=[r'E:\Onedrive\Desktop\Statements',r'E:\Onedrive\Desktop\Statements']
)
('danzhao@','password').send_mail('danzhao@',mail)

Assignment: Write a complete email code that contains the following elements

Multiple recipients, all recipients are externalized as names.
Multiple cc's, with your name on it.
Multiple annexes, with indication of the role of the annexes in the body of the text
Text with formatting: attachments in italics, additions in bold, leader's name in bold red
The theme turns into a content that automatically takes the day's date with it

summarize

to this article on the Python one line of code to achieve automatic e-mail function is introduced to this article, more related Python automatic e-mail content please search for my previous posts or continue to browse the following related articles I hope you will support me in the future more!