通过travis的自动部署功能实现每天给女朋友发一封问候邮件

通过travis的自动部署功能实现每天给女朋友发一封问候邮件

今天偶然间发现了这个仓库:chenjiandongx/email-subscribe,按照作者的描述是可以实现自动问候女朋友。然后我想到我也有女朋友啊,我也可以试试!于是赶紧下载下来研究一番。

先放上原始的代码:

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# !/usr/bin/env python
# coding=utf-8

import os
import datetime
import smtplib
from email.mime.text import MIMEText
from email.header import Header

import requests

GIRL, BOY = "广州", "肇庆"
HEADERS = {
"X-Requested-With": "XMLHttpRequest",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36"
"(KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
}

MAIL_HOST = os.environ.get("MAIL_HOST")
MAIL_USER = os.environ.get("MAIL_USER")
MAIL_PASS = os.environ.get("MAIL_PASS")

RECEIVER = ["[email protected]"]
SENDER = "[email protected]"

# 聚合数据天气预报 api
weather_api = "https://www.sojson.com/open/api/weather/json.shtml?city={}"

# 邮件内容
CONTENT_FORMAT = (
"你好,傻宝宝 😄 :\n\n\t"
"今天是 {_date},{_week}。\n\t"
"首先,今天已经是我们相恋的第 {_loving_days} 天了喔 💓。然后我就要来播送天气预报了!!\n\n\t"
"广州明天{_g_weather_high},{_g_weather_low},天气 {_g_weather_type},"
"需要注意的是{_g_weather_notice}\n\n\t"
"肇庆明天{_b_weather_high},{_b_weather_low},天气 {_b_weather_type},"
"需要注意的是{_b_weather_notice}"
)

ANGRY_MSG = "😠 傻宝宝,这傻逼接口他妈的又挂了喔!"


def get_weather_info():
"""
获取天气信息
"""
girl = requests.get(weather_api.format(GIRL, headers=HEADERS)).json()
boy = requests.get(weather_api.format(BOY, headers=HEADERS)).json()

girl_weather = girl["data"]["forecast"][1]
boy_weather = boy["data"]["forecast"][1]

_date, _week = get_today(girl)

if girl and boy:
return CONTENT_FORMAT.format(
_week=_week,
_date=_date,
_loving_days=get_loving_days(),
_g_weather_high=girl_weather["high"],
_g_weather_low=girl_weather["low"],
_g_weather_type=girl_weather["type"],
_g_weather_notice=girl_weather["notice"],
_b_weather_high=boy_weather["high"],
_b_weather_low=boy_weather["low"],
_b_weather_type=boy_weather["type"],
_b_weather_notice=boy_weather["notice"],
)


def get_loving_days():
"""
获取恋爱天数
"""
today = datetime.datetime.today()
anniversary = datetime.datetime(2015, 7, 2)
return (today - anniversary).days


def get_today(today):
"""
格式化今天日期
"""
date = today["date"]
week = today["data"]["forecast"][0]["date"][-3:]
return "{}-{}-{}".format(date[:4], date[4:6], date[6:]), week


def send_email():
"""
发送邮件
"""
try:
content = get_weather_info()
except Exception:
try:
content = get_weather_info()
except Exception:
content = ANGRY_MSG

message = MIMEText(content, "plain", "utf-8")
message["From"] = Header("暖宝宝", "utf-8")
message["To"] = Header("A handsome soul")
message["Subject"] = Header("😘 男朋友的日常问候", "utf-8")
try:
smtp_obj = smtplib.SMTP_SSL(MAIL_HOST)
smtp_obj.login(MAIL_USER, MAIL_PASS)
smtp_obj.sendmail(SENDER, RECEIVER, message.as_string())
smtp_obj.quit()
except Exception as e:
print(e)


if __name__ == "__main__":
send_email()

仔细看了一下,还是蛮简单的,就是爬取天气预报,然后作为邮件内容发送。所以我首先得会用python发邮件,然后就找了好几篇博客学习。最后发现这位博主的方法最好用:Python进阶(四十六)-Python3实现SMTP发送邮件详细教程。按照上面的方法我又注册了一个新的邮箱,然后开启SMTP协议,注意,这里一定要找一个对你完全无害的邮箱,因为这个邮箱的账号的密码都在代码里,也就是说是公开的。
按照文中的教程,我成功的使用Python发送了邮件,然后我再把chenjiandongx/email-subscribe中的一些代码搬了过来,于是就形成了下面的代码:

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import smtplib
import requests
import datetime
from email.header import Header
from email.mime.text import MIMEText

HEADERS = {
"X-Requested-With": "XMLHttpRequest",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36"
"(KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36",
}

def get_birth_days():
"""
获取网站建立天数
"""
today = datetime.datetime.today()
anniversary = datetime.datetime(2017, 1, 6)
return (today - anniversary).days

def get_today(today):
"""
格式化今天日期
"""
date = today["date"]
week = today["data"]["forecast"][0]["date"][-3:]
return "{}-{}-{}".format(date[:4], date[4:6], date[6:]), week

content = (
"今天是 {_date},{_week},我们已经在一起<strong style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'>{_loving_days}</strong>天啦💖!"
"</td>"
"</tr><tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'><td class='content-block' style='font-family: STSong; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;' valign='top'>"
"<font color = '#FF9F00'><b>☔️首先我跟你讲一下今日的天气昂:</b></font>"
"</td>"
"</tr>"
"<tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'>"
"<td class='content-block' style='font-family: STSong; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;' valign='top'>"
"你那里今天<font color='#E62739'><b>最{_g_weather_high}</font></b>,<b><font color='5E7CE2'>最{_g_weather_low}</font></b>,天气<b><font color='#381F21'>{_g_weather_type}</font></b>,"
"<br>需要注意{_g_weather_notice}哦!<br>"
"<tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'>"
"<td class='content-block' style='font-family: STSong; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;' valign='top'>"
"<details>"
"<summary><strong>查看你那里的详细天气点击这里哦!</strong></summary>"
"<b>阜阳今天</b>: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#f37c3d'><b>日出时间为: {_g_sunrise}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color='#E62739'><b>最{_g_weather_high}</b></font>;</font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color='5E7CE2'>最{_g_weather_low}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#aa3c16'><b>日落时间为: {_g_sunrset}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#f06966'><b>空气质量指数为: {_g_aqi}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#745285'><b>风向为: {_g_fx}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#854e4b'><b>风力大小为: {_g_fl}</b></font>;<br>天气<b><font color='#381F21'>{_g_weather_type}</font></b>,需要注意{_g_weather_notice}哦!<br><br>"
"<b>阜阳明天</b>: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#f37c3d'><b>日出时间为: {_g_sunrise1}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color='#E62739'><b>最{_g_weather_high1}</b></font>;</font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color='5E7CE2'>最{_g_weather_low1}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#aa3c16'><b>日落时间为: {_g_sunrset1}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#f06966'><b>空气质量指数为: {_g_aqi1}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#745285'><b>风向为: {_g_fx1}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#854e4b'><b>风力大小为: {_g_fl1}</b></font>;<br>天气<b><font color='#381F21'>{_g_weather_type1}</font></b>,需要注意{_g_weather_notice1}哦!<br><br>"
"<b>阜阳后天</b>: <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#f37c3d'><b>日出时间为: {_g_sunrise2}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color='#E62739'><b>最{_g_weather_high2}</b></font>;</font><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font color='5E7CE2'>最{_g_weather_low2}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#aa3c16'><b>日落时间为: {_g_sunrset2}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#f06966'><b>空气质量指数为: {_g_aqi2}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#745285'><b>风向为: {_g_fx2}</b></font>;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='#854e4b'><b>风力大小为: {_g_fl2}</b></font>;<br>天气<b><font color='#381F21'>{_g_weather_type2}</font></b>,需要注意{_g_weather_notice2}哦!<br>"
"</details>"
"</td>"
"</tr>"
"<tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'><td class='content-block' style='font-family: STSong; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;' valign='top'>"
)

def get_weather_info():
"""
获取天气信息
"""
weather_api = "https://www.sojson.com/open/api/weather/json.shtml?city={}"
girl = requests.get(weather_api.format("阜阳", headers = HEADERS)).json()
girl_weather = girl['data']['forecast'][0]
girl_weather1 = girl['data']['forecast'][1]
girl_weather2 = girl['data']['forecast'][2]
_date, _week = get_today(girl)
if girl:
return content.format(
_week=_week,
_date=_date,
_loving_days=get_birth_days(),
_g_weather_high=girl_weather["high"],
_g_weather_low=girl_weather["low"],
_g_weather_type=girl_weather["type"],
_g_weather_notice=girl_weather["notice"],
_g_aqi=girl_weather["aqi"],
_g_sunrise=girl_weather["sunrise"],
_g_sunrset=girl_weather["sunset"],
_g_fl=girl_weather["fl"],
_g_fx=girl_weather["fx"],
_g_weather_high1=girl_weather1["high"],
_g_weather_low1=girl_weather1["low"],
_g_weather_type1=girl_weather1["type"],
_g_weather_notice1=girl_weather1["notice"],
_g_aqi1=girl_weather1["aqi"],
_g_sunrise1=girl_weather1["sunrise"],
_g_sunrset1=girl_weather1["sunset"],
_g_fl1=girl_weather1["fl"],
_g_fx1=girl_weather1["fx"],
_g_weather_high2=girl_weather2["high"],
_g_weather_low2=girl_weather2["low"],
_g_weather_type2=girl_weather2["type"],
_g_weather_notice2=girl_weather2["notice"],
_g_aqi2=girl_weather2["aqi"],
_g_sunrise2=girl_weather2["sunrise"],
_g_sunrset2=girl_weather2["sunset"],
_g_fl2=girl_weather2["fl"],
_g_fx2=girl_weather2["fx"],
)

def new_post():
url = "http://www.czxa.top/content.json"
json = requests.get(url.format(headers = HEADERS)).json()['posts']
post = (get_weather_info(),
"<font color = '#FF9F00'><b>然后我要播报一下我最近网站的更新信息啦,别嫌我烦呦,因为很多文章的封面都是你的照片。",
"最近网站更新的文章有:</b></font>",
"</td></tr><tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'>",
"<td class='content-block' style='font-family: STSong; box-sizing: border-box;",
"font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;' valign='top'>")
for i in range(0, 10):
post = post + ("<font color = '#348eda'><b>", json[i]['date'][0:10], ": ", "</b></font><a href=", json[i]['permalink'], ">", json[i]['title'], "</a><br>")
return ''.join(post)

subscribe = (
"<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html xmlns='http://www.w3.org/1999/xhtml' style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'>",
"<head>",
"<meta name='viewport' content='width=device-width' />",
"<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />",
"<title>给笑笑宝宝的~</title>",
"<style type='text/css'>",
"img {",
"max-width: 100%;",
"}",
"body {",
"-webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em;",
"}",
"body {",
"background-color: #f6f6f6;",
"}",
"a:link,a:visited{",
" text-decoration:none;",
"}",
"a:hover{",
" text-decoration:underline;",
"}",
"@media only screen and (max-width: 640px) {",
"body {",
" padding: 0 !important;",
"}",
"h1 {",
" font-weight: 800 !important; margin: 20px 0 5px !important;",
"}",
"h2 {",
" font-weight: 800 !important; margin: 20px 0 5px !important;",
"}",
"h3 {",
" font-weight: 800 !important; margin: 20px 0 5px !important;",
"}",
"h4 {",
" font-weight: 800 !important; margin: 20px 0 5px !important;",
"}",
"h1 {",
" font-size: 22px !important;",
"}",
"h2 {",
" font-size: 18px !important;",
"}",
"h3 {",
" font-size: 16px !important;",
"}",
".container {",
" padding: 0 !important; width: 100% !important;",
"}",
".content {",
" padding: 0 !important;",
"}",
".content-wrap {",
" padding: 10px !important;",
"}",
".invoice {",
" width: 100% !important;",
"}",
"}",
"</style>",
"</head>",
"<body itemscope itemtype='http://schema.org/EmailMessage' style='font-family: STSong; box-sizing: border-box; font-size: 14px; -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: none; width: 100% !important; height: 100%; line-height: 1.6em; background-color: #f6f6f6; margin: 0;' bgcolor='#f6f6f6'>",
"<table class='body-wrap' style='font-family: STSong; box-sizing: border-box; font-size: 14px; width: 100%; background-color: #f6f6f6; margin: 0;' bgcolor='#f6f6f6'><tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'><td style='font-family: STSong; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;' valign='top'></td>",
"<td class='container' width='600' style='font-family: STSong; box-sizing: border-box; font-size: 14px; vertical-align: top; display: block !important;max-width: 600px !important; clear: both !important; margin: 0 auto;' valign='top'>",
"<div class='content' style='font-family: STSong; box-sizing: border-box; font-size: 14px; max-width: 600px; display: block; margin: 0 auto; padding: 20px;'>",
"<table class='main' width='100%' cellpadding='0' cellspacing='0' style='font-family: STSong; box-sizing: border-box; font-size: 14px; border-radius: 3px; background-color: #fff; margin: 0; border: 1px solid #e9e9e9;' bgcolor='#fff'><tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'><td class='alert alert-warning' style='font-family: STSong; box-sizing: border-box; font-size: 16px; vertical-align: top; color: #fff; font-weight: 500; text-align: center; border-radius: 3px 3px 0 0; background-color: #FF9F00; margin: 0; padding: 20px;' align='center' bgcolor='#FF9F00' valign='top'>",
"<b>嗨,宝贝脑婆😘~</b>",
"</td>",
"</tr><tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'><td class='content-wrap' style='font-family: STSong; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 20px;' valign='top'>",
"<table width='100%' cellpadding='0' cellspacing='0' style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'><tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'>",
"<td class='content-block' style='font-family: STSong; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;' valign='top'>")
def news():
url = "http://feed.mix.sina.com.cn/api/roll/get?pageid=153&lid=2509&k=&num=50&page=1"
json = requests.get(url.format(headers = HEADERS)).json()['result']['data']
news = (new_post(),
"</td></tr><tr style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'>",
"<td class='content-block' style='font-family: STSong; box-sizing: border-box; font-size: 14px;",
" vertical-align: top; margin: 0; padding: 0 0 20px;' valign='top'>",
"<font color = '#FF9F00'><b>最后,要保持对新闻的关注哦!再插播一些即时新闻:",
"</b></font></td></tr><tr style='font-family: STSong;",
"box-sizing: border-box; font-size: 14px; margin: 0;'>",
"<td class='content-block' style='font-family: STSong;",
"box-sizing: border-box; font-size: 14px; vertical-align: top;",
"margin: 0; padding: 0 0 20px;' valign='top'>")
for i in range(0, 50):
j = i + 1
if j == 6:
news = news + ("<details>", "<summary><strong>查看更多</strong></summary>")
news = news + ("<font color = '#348eda'><b>", str(j), ": </b></font><a href=", json[i]['url'], ">", json[i]['title'], "</a><br>")
news = subscribe + news + ("</details>", "</td></tr><tr style='font-family: STSong; box-sizing: border-box;",
"font-size: 14px; margin: 0;'><td class='content-block' style='font-family:",
"STSong; box-sizing: border-box; font-size: 14px; vertical-align: top;",
"margin: 0; padding: 0 0 20px;' valign='top'><center><a href='http://www.czxa.top'",
"target='_blank' class='btn-primary' style='font-family: STSong; box-sizing: border-box;",
"font-size: 14px; color: #FFF; text-decoration: none; line-height: 2em; font-weight: bold;",
"text-align: center; cursor: pointer; display: inline-block; border-radius: 5px;",
"text-transform: capitalize; background-color: #348eda; margin: 0; border-color: #348eda;",
"border-style: solid; border-width: 10px 20px;'>常来看看我的网站哦!</a></center></td></tr><tr ",
"style='font-family: STSong; box-sizing: border-box; font-size: 14px; margin: 0;'><td ",
"class='content-block' style='font-family: STSong; box-sizing: border-box; font-size: 14px;",
"vertical-align: top; margin: 0; padding: 0 0 20px;' valign='top'>就这些了,明天见啦!</td></tr></table></td>",
"</tr></table><div class='footer' style='font-family: STSong; box-sizing: border-box; ",
"font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;'>",
"<table width='100%' style='font-family: STSong; box-sizing: border-box; font-size:",
"14px; margin: 0;'><tr style='font-family: STSong; box-sizing: border-box; font-size:",
"14px; margin: 0;'>",
"<tr style='font-family: STSong; box-sizing: ",
"border-box; font-size: 14px; margin: 0;'>",
"<td class='aligncenter content-block' style='font-family: ",
"STSong; font-size: 12px; vertical-align: top; color: #999; ",
"text-align: center; margin: 0; padding: 0 0 20px;'",
"align='center' valign='top'><a href='http://www.czxa.top' style='font-family: STSong; box-sizing: border-box; font-size: 12px; color: #999; text-decoration: underline; margin: 0;'>超级爱你的脑公~</a></td>",
"</tr></table></div></div></td>",
"<td style='font-family: STSong;",
"box-sizing: border-box; font-size: 14px; vertical-align: top;",
"margin: 0;' valign='top'></td></tr></table></body></html>")
return ''.join(news)

title = '脑公的每日问候来啦🧜‍♂️'
mail_host = "smtp.sina.com"
mail_user = "[email protected]"
mail_pass = "zssjmm126,"
sender = '[email protected]'
receivers = ['[email protected]', '[email protected]']
# receivers = ['[email protected]']

def sendEmail():
message = MIMEText(news(), 'html', 'utf-8')
# print(message)
message['From'] = "{}".format(sender)
message['To'] = ",".join(receivers)
message['Subject'] = title
try:
smtpObj = smtplib.SMTP_SSL(mail_host, 465)
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print("邮件发送成功!")
except smtplib.SMTPException as e:
print(e)

if __name__ == '__main__':
sendEmail()

然后就成了,从此我的宝贝笑笑就能每日收到我的问候邮件了!
例如今天的:

上传到github上之后,还需要通过travil部署,这个探索一下很快就明白了,另外在仓库中还需要添加一个.travis.yml文件,我的文件内容是:

1
2
3
4
5
6
7
8
9
10
11
12
13
language: python
notifications:
email:
recipients:
- [email protected]
on_success: change # default: change
on_failure: always # default: always
python:
- 3.6
before_install:
- pip install -r requirements.txt
script:
- python3 xiaoxiao.py

travis部署时会按照这个文件的内容运行代码,然后邮件就发出去啦!

另外我也终于拥有了自己的第一个:

图标了!这个仓库的地址是czxa/pygreet,未来打算加入更多自动发邮件的功能!

# Python

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×