Cải thiện bài viết Lưu bài viết Cải thiện bài viết Lưu bài viết Đọc Bàn luận MIMAPPLICATION: Điều này có thể được sử dụng để thêm bất cứ điều gì hoặc bất kỳ tệp đính kèm nào khác.Import the following modules Thực hiện từng bước Bước 1: Nhập các mô -đun sauMIMEAUDIO: Nếu chúng tôi muốn thêm các tệp âm thanh, chúng tôi có thể thực hiện dễ dàng với sự trợ giúp của lớp con này.
Python3
from
email.mime.text
import
MIMEText
from
schedule.every[2].seconds.do[mail]
1import
schedule.every[2].seconds.do[mail]
3
from
schedule.every[2].seconds.do[mail]5
import
schedule.every[2].seconds.do[mail]7
from
schedule.every[2].seconds.do[mail]9
import
schedule.every[10].minutes.do[mail]1
import
schedule.every[10].minutes.do[mail]
3Let’s set up a connection to our email server.
import
schedule.every[10].minutes.do[mail]
5SMTP connection- Bước 2: Hãy để thiết lập kết nối với máy chủ email của chúng tôi.smtp.ehlo to send an EHLO [Extended Hello] command.
- Cung cấp địa chỉ máy chủ và số cổng để bắt đầu kết nối SMTP của chúng tôismtp.starttls to enable transport layer security [TLS] encryption.
Python3
Sau đó, chúng tôi sẽ sử dụng smtp.ehlo để gửi lệnh ehlo [xin chào mở rộng].
schedule.every[].hour.do[mail]3
schedule.every[].hour.do[mail]4
schedule.every[].hour.do[mail]5
schedule.every[].hour.do[mail]6
schedule.every[].hour.do[mail]0
schedule.every[].hour.do[mail]8
schedule.every[].hour.do[mail]2
Bây giờ, chúng tôi sẽ sử dụng smtp.starttls để cho phép mã hóa bảo mật lớp vận chuyển [TLS].Now, built the message content.
schedule.every[10].minutes.do[mail]
6schedule.every[10].minutes.do[mail]
7schedule.every[10].minutes.do[mail]
8schedule.every[10].minutes.do[mail]
9____________schedule.every[].hour.do[mail]
1schedule.every[].hour.do[mail]
2MIMEMultipart object to the msg variable after initializing it.- Bước 3: Bây giờ, xây dựng nội dung tin nhắn.MIMEText function will be used to attach text.
Python3
Chỉ định đối tượng Mimemultipart cho biến MSG sau khi khởi tạo nó.
Hàm Mimetext sẽ được sử dụng để đính kèm văn bản.
schedule.every[].day.at["10:30"].do[mail]8
schedule.every[].day.at["10:30"].do[mail]
0schedule.every[10].minutes.do[mail]
7 schedule.every[].day.at["10:30"].do[mail]
2Let’s look at how to attach pictures and multiple attachments.
schedule.every[].day.at["10:30"].do[mail]
3schedule.every[].day.at["10:30"].do[mail]
4schedule.every[].day.at["10:30"].do[mail]
5schedule.every[10].minutes.do[mail]
7 schedule.every[].day.at["10:30"].do[mail]
7
- Bước 4: Hãy cùng xem xét cách đính kèm hình ảnh và nhiều tệp đính kèm.
- Đính kèm hình ảnh: & nbsp;MIMEMultipart using MIMEImage, we add the given filename use os.basename
Python3
Đầu tiên, đọc hình ảnh dưới dạng dữ liệu nhị phân.
schedule.every[].monday.do[mail]5
schedule.every[].monday.do[mail]6
schedule.every[].monday.do[mail]7
schedule.every[10].minutes.do[mail]7
schedule.every[].monday.do[mail]9
Đính kèm dữ liệu hình ảnh vào Mimemultipart bằng cách sử dụng mimeimage, chúng tôi thêm tên tệp đã cho sử dụng os.basename
schedule.every[].day.at["10:30"].do[mail]
9schedule.every[10].minutes.do[mail]
7schedule.every[].monday.do[mail]
1schedule.every[].monday.do[mail]
22____53schedule.every[].monday.do[mail]
4MIMEApplication.- Đính kèm một số tệp:
- Đọc trong tệp đính kèm bằng cách sử dụng MIMAPPLICATION.
Python3
Sau đó, chúng tôi chỉnh sửa siêu dữ liệu tệp đính kèm.
Cuối cùng, thêm tệp đính kèm vào đối tượng tin nhắn của chúng tôi.
from
9email.mime.text
0
schedule.every[10].minutes.do[mail]7
email.mime.text
2from
5
schedule.every[].hour.do[mail]2
from
0
schedule.every[].monday.do[mail]1
from
2schedule.every[].monday.do[mail]3
from
4from
5import
3
schedule.every[10].minutes.do[mail]7
import
5import
6from
5import
8from
6
schedule.every[].hour.do[mail]2
from
5from
6 schedule.every[10].minutes.do[mail]
7 from
8The last step is to send the email.
- Các
- Bước 5: Bước cuối cùng là gửi email.sendmail function, pass parameters such as from where, to where, and the message content.
- Lập danh sách tất cả các email bạn muốn gửi.
Python3
Sau đó, bằng cách sử dụng hàm sendmail, hãy truyền các tham số như từ đâu, đến nơi và nội dung tin nhắn.
schedule.every[2].seconds.do[mail]00
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]02
schedule.every[2].seconds.do[mail]03
schedule.every[2].seconds.do[mail]04
schedule.every[2].seconds.do[mail]05
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]07
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]09
schedule.every[2].seconds.do[mail]10
Cuối cùng, chỉ cần thoát kết nối máy chủ.
Python3
Thực hiện từng bước
Bước 1: Nhập các mô -đun sau
from
email.mime.text
import
MIMEText
from
schedule.every[2].seconds.do[mail]1
import
schedule.every[2].seconds.do[mail]3
from
schedule.every[2].seconds.do[mail]5
import
schedule.every[2].seconds.do[mail]7
from
schedule.every[2].seconds.do[mail]9
import
schedule.every[10].minutes.do[mail]1
Sau đó, chúng tôi sẽ sử dụng smtp.ehlo để gửi lệnh ehlo [xin chào mở rộng].
schedule.every[].hour.do[mail]3
schedule.every[].hour.do[mail]4
schedule.every[].hour.do[mail]5
schedule.every[2].seconds.do[mail]41
schedule.every[].hour.do[mail]0
schedule.every[].hour.do[mail]8
schedule.every[].hour.do[mail]2
Bây giờ, chúng tôi sẽ sử dụng smtp.starttls để cho phép mã hóa bảo mật lớp vận chuyển [TLS].
schedule.every[2].seconds.do[mail]50
schedule.every[2].seconds.do[mail]51
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]53
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]55
schedule.every[2].seconds.do[mail]03
schedule.every[2].seconds.do[mail]50
schedule.every[2].seconds.do[mail]58
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]55
schedule.every[2].seconds.do[mail]61
schedule.every[10].minutes.do[mail]6
schedule.every[10].minutes.do[mail]7
schedule.every[10].minutes.do[mail]8
schedule.every[10].minutes.do[mail]9____________
schedule.every[].hour.do[mail]1
schedule.every[].hour.do[mail]2
Bước 3: Bây giờ, xây dựng nội dung tin nhắn.
from
5
schedule.every[2].seconds.do[mail]73
Chỉ định đối tượng Mimemultipart cho biến MSG sau khi khởi tạo nó.
Hàm Mimetext sẽ được sử dụng để đính kèm văn bản.
schedule.every[].day.at["10:30"].do[mail]0
schedule.every[10].minutes.do[mail]7
schedule.every[].day.at["10:30"].do[mail]2
schedule.every[].day.at["10:30"].do[mail]3
schedule.every[].day.at["10:30"].do[mail]4
schedule.every[].day.at["10:30"].do[mail]5
schedule.every[10].minutes.do[mail]7
schedule.every[].day.at["10:30"].do[mail]7
Bước 4: Hãy cùng xem xét cách đính kèm hình ảnh và nhiều tệp đính kèm.
schedule.every[2].seconds.do[mail]50
schedule.every[10].minutes.do[mail]06
schedule.every[10].minutes.do[mail]07
schedule.every[].monday.do[mail]7
schedule.every[10].minutes.do[mail]7
schedule.every[].monday.do[mail]9
Đính kèm hình ảnh: & nbsp;
Đầu tiên, đọc hình ảnh dưới dạng dữ liệu nhị phân.
Đính kèm dữ liệu hình ảnh vào Mimemultipart bằng cách sử dụng mimeimage, chúng tôi thêm tên tệp đã cho sử dụng os.basename
schedule.every[].day.at["10:30"].do[mail]9
schedule.every[10].minutes.do[mail]7
schedule.every[].monday.do[mail]1
schedule.every[].monday.do[mail]22____53
schedule.every[].monday.do[mail]4
schedule.every[2].seconds.do[mail]50
from
0schedule.every[].monday.do[mail]1
from
2schedule.every[].monday.do[mail]3
from
4Đính kèm một số tệp:
schedule.every[10].minutes.do[mail]45
schedule.every[10].minutes.do[mail]46
schedule.every[10].minutes.do[mail]45
schedule.every[].monday.do[mail]7
schedule.every[10].minutes.do[mail]7
email.mime.text
2schedule.every[10].minutes.do[mail]41
schedule.every[].hour.do[mail]2
Các
schedule.every[2].seconds.do[mail]50
import
3schedule.every[10].minutes.do[mail]7
import
5import
6schedule.every[2].seconds.do[mail]50
import
8from
6schedule.every[].hour.do[mail]2
from
5
schedule.every[10].minutes.do[mail]70
schedule.every[10].minutes.do[mail]71
schedule.every[].day.at["10:30"].do[mail]0
schedule.every[10].minutes.do[mail]7
schedule.every[10].minutes.do[mail]74
schedule.every[10].minutes.do[mail]75
schedule.every[].hour.do[mail]0
schedule.every[10].minutes.do[mail]777710103
schedule.every[2].seconds.do[mail]04
schedule.every[10].minutes.do[mail]80
schedule.every[10].minutes.do[mail]81
schedule.every[2].seconds.do[mail]03
schedule.every[2].seconds.do[mail]04
schedule.every[10].minutes.do[mail]80
schedule.every[10].minutes.do[mail]85
schedule.every[].hour.do[mail]2
MIMEText
1
schedule.every[10].minutes.do[mail]7
email.mime.text
77____94schedule.every[2].seconds.do[mail]03
schedule.every[10].minutes.do[mail]92
MIMEText
4schedule.every[].hour.do[mail]0
MIMEText
4MIMEText
9schedule.every[2].seconds.do[mail]00
schedule.every[10].minutes.do[mail]7
MIMEText
4schedule.every[2].seconds.do[mail]03
schedule.every[2].seconds.do[mail]04
schedule.every[2].seconds.do[mail]05
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]07
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]09
schedule.every[2].seconds.do[mail]10
Output:
Lên lịch tin nhắn email
Để lên lịch thư, chúng tôi sẽ sử dụng gói lịch trình trong Python. Nó rất nhẹ và dễ sử dụng. & NBSP;schedule package in python. It is very lightweight and easy to use.
Cài đặt mô -đun & nbsp;
pip install schedule
Bây giờ hãy nhìn vào các chức năng khác nhau được xác định trong một mô -đun lịch trình và việc sử dụng chúng:schedule module and their use:
Hàm dưới đây sẽ gọi thư chức năng cứ sau 2 giây.
schedule.every[2].seconds.do[mail]
Điều này sẽ gọi thư chức năng cứ sau 10 phút.
schedule.every[10].minutes.do[mail]
Điều này sẽ gọi chức năng trong mỗi giờ.
schedule.every[].hour.do[mail]
Gọi mỗi ngày lúc 10:30 sáng.
schedule.every[].day.at["10:30"].do[mail]
Gọi một ngày cụ thể.
schedule.every[].monday.do[mail]
Dưới đây là việc thực hiện:
Python3
import
schedule.every[].hour.do[mail]09
import
schedule.every[].hour.do[mail]11
from
email.mime.text
import
MIMEText
from
schedule.every[2].seconds.do[mail]1
import
schedule.every[2].seconds.do[mail]3
from
schedule.every[2].seconds.do[mail]5
import
schedule.every[2].seconds.do[mail]7
from
schedule.every[2].seconds.do[mail]9
import
schedule.every[10].minutes.do[mail]1
import
schedule.every[10].minutes.do[mail]3
import
schedule.every[10].minutes.do[mail]5
schedule.every[2].seconds.do[mail]45
schedule.every[2].seconds.do[mail]46
schedule.every[10].minutes.do[mail]7____
schedule.every[2].seconds.do[mail]48
schedule.every[2].seconds.do[mail]49
schedule.every[2].seconds.do[mail]50
schedule.every[2].seconds.do[mail]51
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]53
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]55
schedule.every[].hour.do[mail]43
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]55
schedule.every[2].seconds.do[mail]61
from
5
schedule.every[].day.at["10:30"].do[mail]0
schedule.every[10].minutes.do[mail]7
schedule.every[].day.at["10:30"].do[mail]2
from
5
schedule.every[].day.at["10:30"].do[mail]3
schedule.every[].day.at["10:30"].do[mail]4
schedule.every[].day.at["10:30"].do[mail]5
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]71
from
5
schedule.every[2].seconds.do[mail]73
from
5
schedule.every[2].seconds.do[mail]75
schedule.every[2].seconds.do[mail]76
schedule.every[2].seconds.do[mail]77
schedule.every[2].seconds.do[mail]78
schedule.every[2].seconds.do[mail]55
schedule.every[2].seconds.do[mail]80
from
9
schedule.every[2].seconds.do[mail]75
schedule.every[2].seconds.do[mail]83
schedule.every[2].seconds.do[mail]84
schedule.every[2].seconds.do[mail]77
schedule.every[2].seconds.do[mail]78
schedule.every[2].seconds.do[mail]87__
schedule.every[2].seconds.do[mail]50
schedule.every[2].seconds.do[mail]76
schedule.every[10].minutes.do[mail]7
schedule.every[].hour.do[mail]77
from
9
schedule.every[2].seconds.do[mail]94
schedule.every[2].seconds.do[mail]95
schedule.every[2].seconds.do[mail]96
schedule.every[2].seconds.do[mail]97
schedule.every[2].seconds.do[mail]50
schedule.every[].day.at["10:30"].do[mail]9
schedule.every[10].minutes.do[mail]7
schedule.every[].monday.do[mail]1
schedule.every[].monday.do[mail]2
schedule.every[].monday.do[mail]3
schedule.every[10].minutes.do[mail]04
schedule.every[2].seconds.do[mail]50
schedule.every[].monday.do[mail]5
schedule.every[10].minutes.do[mail]07
schedule.every[].monday.do[mail]7
schedule.every[10].minutes.do[mail]7
schedule.every[].monday.do[mail]9
from
5
schedule.every[2].seconds.do[mail]75
schedule.every[10].minutes.do[mail]13
schedule.every[2].seconds.do[mail]77
schedule.every[2].seconds.do[mail]78
schedule.every[2].seconds.do[mail]55
schedule.every[2].seconds.do[mail]80
from
9
schedule.every[2].seconds.do[mail]75
schedule.every[2].seconds.do[mail]83
schedule.every[10].minutes.do[mail]21
schedule.every[2].seconds.do[mail]77
schedule.every[2].seconds.do[mail]78
schedule.every[2].seconds.do[mail]87
schedule.every[2].seconds.do[mail]80
schedule.every[2].seconds.do[mail]50
schedule.every[10].minutes.do[mail]13
schedule.every[10].minutes.do[mail]7
schedule.every[10].minutes.do[mail]29
from
9
schedule.every[2].seconds.do[mail]94
schedule.every[10].minutes.do[mail]32
schedule.every[2].seconds.do[mail]96
schedule.every[10].minutes.do[mail]34
schedule.every[2].seconds.do[mail]50
from
0schedule.every[].monday.do[mail]1
from
2schedule.every[].monday.do[mail]3
from
4schedule.every[10].minutes.do[mail]41
from
6 schedule.every[10].minutes.do[mail]7
from
8schedule.every[10].minutes.do[mail]45
schedule.every[10].minutes.do[mail]46
schedule.every[10].minutes.do[mail]45
schedule.every[].monday.do[mail]7
schedule.every[10].minutes.do[mail]7
email.mime.text
2schedule.every[10].minutes.do[mail]41
schedule.every[].hour.do[mail]2
Các
schedule.every[2].seconds.do[mail]50
import
3schedule.every[10].minutes.do[mail]7
import
5import
6schedule.every[2].seconds.do[mail]50
import
8from
6schedule.every[].hour.do[mail]2
from
5
schedule.every[10].minutes.do[mail]70
schedule.every[10].minutes.do[mail]71
schedule.every[2].seconds.do[mail]45
schedule.every[].day.at["10:30"].do[mail]58
from
5
schedule.every[10].minutes.do[mail]6
schedule.every[10].minutes.do[mail]7
schedule.every[10].minutes.do[mail]8
schedule.every[10].minutes.do[mail]9
schedule.every[].hour.do[mail]0
schedule.every[].hour.do[mail]1
schedule.every[].hour.do[mail]2
from
5
schedule.every[].hour.do[mail]3
from
5
schedule.every[].hour.do[mail]4
from
5
schedule.every[].hour.do[mail]5
schedule.every[].day.at["10:30"].do[mail]73
schedule.every[].hour.do[mail]0
schedule.every[].day.at["10:30"].do[mail]75
schedule.every[].hour.do[mail]2
from
5
schedule.every[].day.at["10:30"].do[mail]0
schedule.every[10].minutes.do[mail]7
schedule.every[10].minutes.do[mail]74
schedule.every[10].minutes.do[mail]75
schedule.every[].hour.do[mail]0
schedule.every[10].minutes.do[mail]777
schedule.every[2].seconds.do[mail]03
schedule.every[].day.at["10:30"].do[mail]85
schedule.every[10].minutes.do[mail]80
schedule.every[10].minutes.do[mail]81
schedule.every[2].seconds.do[mail]03
schedule.every[].day.at["10:30"].do[mail]85
schedule.every[10].minutes.do[mail]80
schedule.every[10].minutes.do[mail]85
schedule.every[].hour.do[mail]2
from
5MIMEText
1
schedule.every[10].minutes.do[mail]7
email.mime.text
7MIMEText
4schedule.every[2].seconds.do[mail]03
schedule.every[].day.at["10:30"].do[mail]99
MIMEText
4schedule.every[].hour.do[mail]0
MIMEText
4MIMEText
9from
5
schedule.every[2].seconds.do[mail]00
schedule.every[10].minutes.do[mail]7
MIMEText
4schedule.every[2].seconds.do[mail]03
schedule.every[].day.at["10:30"].do[mail]85
schedule.every[2].seconds.do[mail]05
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]07
schedule.every[10].minutes.do[mail]7
schedule.every[2].seconds.do[mail]09
from
5
schedule.every[].monday.do[mail]16
schedule.every[].monday.do[mail]17
schedule.every[].monday.do[mail]18
schedule.every[].monday.do[mail]19
schedule.every[].monday.do[mail]17
schedule.every[].monday.do[mail]21
schedule.every[].monday.do[mail]22
schedule.every[].monday.do[mail]23
schedule.every[].monday.do[mail]24
schedule.every[].monday.do[mail]25
schedule.every[].monday.do[mail]26
schedule.every[].monday.do[mail]17
schedule.every[].monday.do[mail]28
schedule.every[].monday.do[mail]29
schedule.every[].monday.do[mail]21
schedule.every[].monday.do[mail]22
schedule.every[].monday.do[mail]32
schedule.every[].monday.do[mail]33
schedule.every[].monday.do[mail]34
schedule.every[].monday.do[mail]26
schedule.every[].monday.do[mail]36
schedule.every[].monday.do[mail]37
schedule.every[].monday.do[mail]26
schedule.every[].monday.do[mail]39
schedule.every[].monday.do[mail]40
schedule.every[2].seconds.do[mail]80
from
5
schedule.every[].monday.do[mail]43
from
5
schedule.every[].monday.do[mail]45
schedule.every[].monday.do[mail]46
schedule.every[].hour.do[mail]2
Output:
Bỏ phiếu cho khó khăn
Khó khăn hiện tại: Trung bình