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