1 changed files with 28 additions and 28 deletions
@ -1,28 +1,28 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
import smtplib |
import smtplib |
||||
from email.mime.text import MIMEText |
from email.mime.text import MIMEText |
||||
import urllib.request |
import urllib.request |
||||
|
|
||||
def sendmail(receiver, subject, content): |
def sendmail(receiver, subject, content): |
||||
try: |
try: |
||||
email_host = 'smtp.sina.com' # 发送者是sina邮箱 |
email_host = 'smtp.sina.com' # 发送者是sina邮箱 |
||||
email_user = 'xxxxx@sina.com' # 发送者账号 |
email_user = 'xxxxx@sina.com' # 发送者账号 |
||||
email_pwd = 'Wj12345' # 发送者密码 |
email_pwd = 'Abc12345' # 发送者密码 |
||||
# maillist = 'test123@yeah.net' # 接收者账号,本来想写成[]list的,但是报错,还没解决! |
# maillist = 'test123@yeah.net' # 接收者账号,本来想写成[]list的,但是报错,还没解决! |
||||
|
|
||||
# 三个参数:第一个为文本内容,第二个 html 设置文本格式,第三个 utf-8 设置编码 |
# 三个参数:第一个为文本内容,第二个 html 设置文本格式,第三个 utf-8 设置编码 |
||||
msg = MIMEText(content, 'html', 'utf-8') # 邮件内容 |
msg = MIMEText(content, 'html', 'utf-8') # 邮件内容 |
||||
msg['Subject'] = subject # 邮件主题 |
msg['Subject'] = subject # 邮件主题 |
||||
msg['From'] = email_user # 发送者账号 |
msg['From'] = email_user # 发送者账号 |
||||
msg['To'] = ','.join(receiver) # 接收者账号列表(列表没实现) |
msg['To'] = ','.join(receiver) # 接收者账号列表(列表没实现) |
||||
|
|
||||
smtp = smtplib.SMTP(email_host) # 如上变量定义的,是163邮箱 |
smtp = smtplib.SMTP(email_host) # 如上变量定义的,是163邮箱 |
||||
smtp.login(email_user, email_pwd) # 发送者的邮箱账号,密码 |
smtp.login(email_user, email_pwd) # 发送者的邮箱账号,密码 |
||||
smtp.sendmail(email_user, receiver, msg.as_string()) # 参数分别是发送者,接收者,第三个不知道 |
smtp.sendmail(email_user, receiver, msg.as_string()) # 参数分别是发送者,接收者,第三个不知道 |
||||
smtp.quit() # 发送完毕后退出smtp |
smtp.quit() # 发送完毕后退出smtp |
||||
return True |
return True |
||||
except: |
except: |
||||
return False |
return False |
||||
|
|
||||
if __name__ == '__main__': |
if __name__ == '__main__': |
||||
sendmail(['abc123@yeah.net','xxxxx@163.com','abc123@cz.gov.cn'],'测试邮件','测试邮件,以下是测试内容!') |
sendmail(['abc123@yeah.net','xxxxx@163.com','abc123@cz.gov.cn'],'测试邮件','测试邮件,以下是测试内容!') |
||||
|
Loading…
Reference in new issue