从Postgresql发送邮件时出现错误

时间:2019-12-12 05:00:37

标签: python postgresql smtp

我正在尝试使用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"

0 个答案:

没有答案