# /usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 18-8-20 上午9:52
# @Author : xxx
# @Email : xxxxxxxx
# @File : email_send_msg.py
# @Software: PyCharm
import smtplib
from email.mime.text import MIMEText # 引入smtplib和MIMEText
import json
name = '今日头条'
original_url = 'www.baidu.com'
image_urls = ["www.image1","www.image2","www.image3"]
dict_msg = {'source':'今日头条','original_url':original_url,'image_urls':image_urls}
str_msg = json.dumps(dict_msg)
print(str_msg)
host = 'smtp.163.com' # 设置发件服务器地址
port = 25 # 设置发件服务器端口号。注意,这里有SSL和非SSL两种形式
sender = 'xxxxxxx@163.com' # 设置发件邮箱,一定要自己注册的邮箱
pwd = 'xxxxxxx' # 设置发件邮箱的密码,等会登陆会用到
receiver = 'xxxxxxxxxx@qq.com' # 设置邮件接收人,可以是扣扣邮箱
receiver_1 = 'xxxxxxxxxxx@qq.com' # 设置邮件接收人,可以是扣扣邮箱
body = str_msg # 设置邮件正文,这里是支持HTML的
msg = MIMEText(body, 'html') # 设置正文为符合邮件格式的HTML内容
msg['subject'] = 'Hello Python' # 设置邮件标题
msg['from'] = sender # 设置发送人
msg['to'] = receiver # 设置接收人
try:
s = smtplib.SMTP(host, port) # 注意!如果是使用SSL端口,这里就要改为SMTP_SSL
s.login(sender, pwd) # 登陆邮箱
s.sendmail(sender, [receiver], msg.as_string()) # 发送邮件!如果多个邮箱 则使用列表
print('Done')
s.quit()
except smtplib.SMTPException:
print('***************')