-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81aef4d
commit eb1acf2
Showing
4 changed files
with
362 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
在实际开发中,当你收到一个需求的时候,比如要做一个「收发邮件」的功能。 | ||
|
||
如果你完全没有印象,没有思路,可以直接 Google 搜索的。 | ||
|
||
因为我们不可能对每个知识点都了解,不了解不可耻,但要懂得怎么去找资料了解。 | ||
|
||
强调一下, | ||
|
||
用 Google 搜索。 | ||
|
||
用 Google 搜索。 | ||
|
||
用 Google 搜索。 | ||
|
||
恕我直言,百度搜索是真的辣鸡。 | ||
|
||
那我们怎么去找资料呢? | ||
|
||
首先我们可以直接 Google 「Python 收发邮件」,就可以得到这么一个结果。 | ||
|
||
 | ||
|
||
这种常用的需求,基本只要看前几个就能知道大概的思路了。 | ||
|
||
可以看到,用 Python 实现邮件的收发,主要用到 smtplib 和 email这两个模块。 | ||
|
||
|
||
至于这些模块怎么用,直接看 [Python 官方文档](https://docs.python.org/3.7/library/smtplib.html?highlight=smtplib) | ||
|
||
 | ||
|
||
真的,没有任何教程比官方文档资料还全。 | ||
|
||
不过我们可以总结一下这些内容。 | ||
|
||
**1、SMTP 发送邮件** | ||
|
||
Python 发送邮件主要步骤如下: | ||
|
||
* `import smtplib` | ||
- 导入 `smtplib` 模块,主要用于构造传输服务的 | ||
* `server = smtplib.SMTP()` | ||
- SMTP 是 smtplib 模块中的一个类(class),实例化这个类,方便我们调用他里面的方法。 | ||
- SMTP (Simple Mail Transfer Protocol)翻译过来是“简单邮件传输协议”的意思,SMTP 协议是由源服务器到目的地服务器传送邮件的一组规则。 | ||
* `server.connect(host, port)` | ||
- 连接(connect)指定的服务器 | ||
- host 是指定连接的邮箱服务器,你可以指定服务器的域名。 | ||
- port 服务器的端口号 | ||
- 这些怎么找到,好比 qq 邮箱,在「设置」那里就有相关的开关和说明。 | ||
-  | ||
- 点相关的说明,你就能看到对应的服务器地址和端口号了 | ||
-  | ||
* `server.login(username, password)` | ||
- 登录的账号密码 | ||
* `server.sendmail(from_addr, to_addr, msg)` | ||
- 发送邮件,发送邮件一般是谁发给了谁,发送了什么?总结为也就是三个参数,发送者,接受者,发送邮件的内容。 | ||
- from_addr:邮件发送地址 | ||
- to_addr:邮件收件人地址 | ||
- msg : 发送邮件的内容,邮件内容需要用到 `email` 模块。通过 `email` 模块我们可以定义邮件的主题,收件人信息,发件人信息等等。 | ||
* `server.quit()` | ||
- 退出服务 | ||
|
||
直接看下例子,给 QQ 邮箱发送一个邮件: | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -126,6 +126,7 @@ IT 行业相对于一般传统行业,发展更新速度更快,一旦停止 | |
|
||
|
||
|
||
|
||
# 知识点补漏 | ||
* [Python 关键字 yield](/Article/supplement/Python关键字yield.md) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
eb1acf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢
eb1acf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我在git clone时,自己搭建ss:ssr服务器.md这个文件没有clone下来,只有:自己搭建ss这几个字为什么
eb1acf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢
eb1acf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
非常不错,感谢
eb1acf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
老哥稳得一比
eb1acf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
厉害
eb1acf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eb1acf2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.