- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Django 的新手,但我已经阅读了大约 50 页(主要是 SO 和 Django 文档),但没有找到适合我的情况的内容。
我只是想通过 Django 中的 send_mail 函数发送电子邮件;虽然我希望通过 Gmail 上的 SMTP 使它工作,但现在它甚至不能通过本地主机工作。当我运行测试此 send_mail 函数的 test_email.py 文件时,出现以下错误:
ConnectionRefusedError: [WinError 10061] 由于目标机器主动拒绝,无法建立连接
当我在 shell 中运行相同的 send_mail 调用时(通过 python manage.py shell),它完全没问题,并按照我的预期显示电子邮件。只有一次我尝试在 Django 中运行它时才会弹出错误。请注意,无论我在 settings.py 文件中放入以下 2 组设置的哪种排列,我都会收到上述错误:
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 1025
EMAIL_HOST_USER = 'myemail@gmail.com'
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False
我还在我的 settings.py 文件中尝试了以下设置,以及这些设置与之前设置的各种混合(尽管我想我已经超前看到 localhost 是如何不工作的):
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = 'myemail@gmail.com' # Note I'm using my actual gmail address here in real life
EMAIL_HOST_PASSWORD = '****' # Note I'm using my actual gmail password here in real life
DEFAULT_FROM_EMAIL = 'myemail@gmail.com' # Note I'm using my actual gmail address here in real life
SERVER_EMAIL = 'myemail@gmail.com' # Note I'm using my actual gmail address here in real life
当我尝试运行本地主机路由时,我在旁边的 CMD 提示符下运行以下命令:
python -m smtpd -n -c DebuggingServer localhost:1025
这是我尝试在 Django 中运行的 test_email.py 文件,我在其中遇到连接被拒绝的错误:
from django.core.mail import send_mail,EmailMessage
from django.conf import settings
settings.configure()
# Create your tests here.
# Email test #1: send email from my personal email to myself
send_mail(
'Email Test #1',
'Test if I can send email from my personal Gmail account to another email account via Django project.',
settings.EMAIL_HOST_USER,
['myemail@gmail.com'],
fail_silently=False
)
任何关于为什么这甚至不能通过本地主机工作的想法或关于其他尝试的建议都将不胜感激。
谢谢!
最佳答案
我认为 gmail smtp
服务有问题。尝试使用 smtp
服务表单 sendgrid .它的基本使用也是免费的。我之前也遇到过同样的问题。
在项目settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.sendgrid.net'
EMAIL_HOST_USER = 'sendgridusername'
EMAIL_HOST_PASSWORD = 'sedgridpasseord'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
DEFAULT_FROM_EMAIL = 'yourmail@site.com'
still error
Try if `smtp` service is working on your your server.
关于python - Django - 发送电子邮件在 shell 中有效,但在本地主机上无效 - ConnectionRefusedError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46166699/
我有一个非常基本的代理类(一个帮我编码的 friend 坚称它是一个装饰器类)python-mpd2 . 类看起来是这样的 import mpd class MPDProxy: def __i
我尝试使用 python 连接 mySql 服务器,这是我的代码(当然我将数据库详细信息更改为假的): import pymysql connMySql= pymysql.connec
我使用 asyncio 与我正在开发的 BitTorrent 客户端中的其他对等点进行连接。当某些对等点无法连接时,程序会崩溃并出现 ConnectionRefusedError 和 TimeoutE
我有一个连接到 FTP 服务器的简单脚本: from ftplib import FTP # Here is fine ftp = FTP(host='') ftp.login(user='', pa
我正在尝试使用 Python 捕获套接字连接中的错误。我需要处理两种不同类型的错误[ ConnectionRefusedError, OSError ]。我想对每个错误执行不同的操作,所以我用 (tr
我的脚本应该从本地 IP 读取 json(例如 http://192.168.1.10/last_data.json)。我与 requests 建立连接,但经常收到此错误: ConnectionRef
所以我知道下面有很多代码要看,但我完全被难住了,因为我在使用 python 时从未遇到过这样的问题。 我希望使用请求模块来帮助我加快一些基于 Web 的工作事件。我根据开发人员的要求下载了 zipba
我正在尝试通过我的 Gmail 帐户为我的 Django 应用程序发送电子邮件。我在 settings.py 文件中使用以下配置。 EMAIL_BACKEND = 'django.core.mail.
所以今天我使用了自己编写的脚本,但我发现有些问题。我使用多重处理运行了我的程序几个小时,然后遇到了不同的错误。 第一个是: 第二个是: 最后一张: Traceback (most recent cal
我是 Django 的新手,但我已经阅读了大约 50 页(主要是 SO 和 Django 文档),但没有找到适合我的情况的内容。 我只是想通过 Django 中的 send_mail 函数发送电子邮件
我有一个 python 程序,它使用 selenium 访问站点并获取元素的值。现在,我有一个字典列表,每个字典都有一个 url 参数。我遍历列表并从每个字典转到 url。问题是在循环的第一次运行之后
我正在尝试运行一个简单的 Flask API,但它没有按预期工作。我在 Python 方面不是很有经验,所以发现错误并解决它非常具有挑战性。如果有人可以提供帮助,我将不胜感激。 系统设置如下: Ubu
我尝试通过 Tor 使用 python 请求发出请求,但收到错误“ConnectionRefusedError: [WinError 10061] 无法建立连接,因为目标计算机主动拒绝它”。 这是我正
我有一个应该连接到 FTP 的脚本 from ftplib import FTP with FTP('IP') as ftp: ftp.login(user='my user', passwd=
我已经阅读了许多尝试实现的解决方案,但没有成功。请建议解决此问题,下面是我的代码中实现的内容。 在views.py文件中 s = smtplib.SMTP(IP Address, Port)
我正在使用 Django 发送电子邮件。我显然遇到了一个常见的网络错误,但我读过的所有答案都没有解决。我相信我的套接字有问题, 当我发送电子邮件时,出现以下错误: Traceback (most re
我有一个 Python 3.5 脚本,可以从另一个 Linux 服务器中提取信息。必须先通过443端口建立连接。不幸的是,我收到以下错误消息: 我可以 ping 通 Linux 服务器,但出现以下错误
我正在做一项关于使用客户端和服务器在 python 中进行套接字编程的作业。我目前使用的是 Windows 10。在进入作业的小细节之前,我一直在尝试简单地连接服务器和客户端。 每次我尝试运行客户端文
我正在尝试做 docker-compose up命令在我的终端。首先,我导航到找到 docker-compose.yaml 的文件目录。然后我写命令。服务器在端口 80 上。我收到以下错误: Trac
我想调试我的本地 Python代码照常在 VS-Code在 Windows 10通过按 F5 : 我在一年多前就开始遇到这个错误,但最近它变得持续存在。 整个错误回溯: $ /usr/bin/env
我是一名优秀的程序员,十分优秀!