首页 > 解决方案 > 从 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"

标签: pythonpostgresqlsmtp

解决方案


推荐阅读