forked from capricorntb/AutoPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_email_with_python
More file actions
44 lines (39 loc) · 1.05 KB
/
Copy pathsend_email_with_python
File metadata and controls
44 lines (39 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#! /usr/bin/env python
# coding:utf-8
'''
[INFORMATION]
Send Email With Python
AUTHOR : Wing
GitHub : https://github.com/wing324
Email : [email protected]
'''
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
def send_mail(to_email,message):
# 定义邮件发送
# Define send_mail() function
smtp_host = 'smtp.xxx.com'
# 发件箱服务器
# Outbox Server
# 发件邮箱
# from_email
passwd = 'xxxxxx'
# 发件邮箱密码
# from_email_password
msg = MIMEText(message,'plain','utf-8')
msg['Subject'] = Header(u'Email Subject','utf-8').encode()
# 邮件主题
# Email Subject
smtp_server = smtplib.SMTP(smtp_host,25)
# 发件服务器端口
# Outbox Server Port
smtp_server.login(from_email,passwd)
smtp_server.sendmail(from_email,[to_email],msg.as_string())
smtp_server.quit()
# 发送邮件('收件邮箱','邮件正文内容')
# send_mail('to_email','Email Context')