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