Rai*_*ers 3 python gmail smtp pyramid
我正在尝试使用我的 gmail smtp 和金字塔邮件程序包从我的金字塔网站发送电子邮件。首先,如果有人对电子邮件解决方案有其他建议,请告诉我!
我将以下内容添加到我的 dev.ini 中:
mail.host = smtp.gmail.com
mail.username = user@gmail.com
mail.password = password
mail.port = 465
mail.ssl = True
Run Code Online (Sandbox Code Playgroud)
然后我像这样发送消息:
config.registry['mailer'] = Mailer.from_settings(settings)
Run Code Online (Sandbox Code Playgroud)
然后...
mailer = request.registry['mailer']
message = Message(subject="hello world",
sender="admin@mysite.com",
recipients=["someaddress@gmail.com"],
body="hello!")
mailer.send(message)
Run Code Online (Sandbox Code Playgroud)
不幸的是,我得到以下异常:
SMTPServerDisconnected: please run connect() first
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
谢谢!
以下设置对我有用:
# pyramid_mailer
mail.host = smtp.gmail.com
mail.port = 587
mail.username = my.login@gmail.com
mail.password = mypassword
mail.tls = True
Run Code Online (Sandbox Code Playgroud)
您的邮件发送代码似乎与我的相同,所以应该可以工作。
我还没有尝试过 SSL,但我假设可能存在各种错误。