python - 从 postgresql 发送邮件时出错
问题描述
我正在尝试使用 plpythonu 扩展从 postgresql 发送一封简单的邮件。有人可以帮我解决这个问题吗?
CREATE OR REPLACE FUNCTION "PUBLIC".send_email()
RETURNS integer
LANGUAGE plpythonu
AS $function$
import smtplib
server = smtplib.SMTP('mailhost.XXX.com',587)
server.sendmail("Xyz@mail.com", "abc@mail.com", "hi")
return 0
$function$
在执行时我得到以下错误。
SQL Error [38000]: ERROR: smtplib.SMTPServerDisconnected: Connection unexpectedly closed: [Errno 10054] An existing connection was forcibly closed by the remote host
Where: Traceback (most recent call last):
PL/Python function "send_email", line 5, in <module>
server = smtplib.SMTP('mailhost.XXX.com',587)
PL/Python function "send_email", line 255, in __init__
PL/Python function "send_email", line 316, in connect
PL/Python function "send_email", line 364, in getreply
PL/Python function "send_email"
解决方案
推荐阅读
- python - 为什么scrapy返回错误说“'LoginSpider'对象没有属性'logged_in'”?
- java - 了解静态和实例成员
- reactjs - 获取数据后如何设置状态反应钩子
- angular - SwaggerUI - 如何在 Angular 9 中为 SwaggerUI 外部创建自定义布局和插件
- c# - 我该怎么做 if(在 if == "x")
- design-patterns - 我如何管理一些设计模式来解决这个问题
- unit-testing - 如何优雅地测试 Go 中包含多个客户端的方法?
- javascript - 在数组表js中插入值
- ios - 我如何在我的 Mac 应用程序上读取应用程序 iPhone 输出?
- linux - 在某些特定情况下没有从 ProcessBuilder 的输入流中得到响应