python - 如何使用 python 请求将电子邮件发送到本地电子邮件服务器
问题描述
我已经设置了一个本地电子邮件服务器,如下所述:
https://gist.github.com/raelgc/6031274
我使用以下 python 代码尝试发送电子邮件:
import requests
requests.post('http://localhost.com')
我收到以下错误:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost.com', port=80): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f0c75631f10>: Failed to establish a new connection: [Errno 111] Connection refused',))
我尝试禁用防火墙 ( sudo ufw disable
),指定 pop3 和 IMAP 端口并使用不同的方案,但我继续收到此错误。
我怀疑这可能是因为requests
只支持http。如果是这样,那么我如何实现使用requests
.
解决方案
Postfix 是一个邮件服务器,使用 TCP 端口 25、465 和 587。它使用 SMTP 进行通信,据我所知,没有可用的 API 接口。如果你想发送需要 smtplib 的电子邮件,请求将不起作用。
带有后缀服务器的 python smtplib 示例:http: //masnun.com/2010/01/01/sending-mail-via-postfix-a-perfect-python-example.html
推荐阅读
- javascript - 同一句子中具有两种不同字体大小的画布文本
- mongodb - 如何在一个本地系统中配置两台 MongoDB 服务器?
- javascript - 如何制作一个取消选中所有复选框并更改 div 的背景颜色的按钮?
- javascript - 为什么“meteor npm install”不能在 gitpod 工作区上运行?
- unity3d - 带有相机的画布屏幕空间的奇怪行为?
- rabbitmq - 我有一个经常出现“unexpected_frame”异常的 RabbitMQ 容器,这是什么意思?
- python - Python子进程nmap输出不同于终端命令
- python - 在两个值之间选择 Pandas DF
- c++ - 为什么 C++20 不提供范围/约束版本的算法
? - spring - spring testRestTemplate 基本身份验证不适用于 POST 请求 Httpstatus 302