ahoj, prednedavnom som hladal funkciu v PostreSQL, ktora by bola schopna odoslat email a bolo by ju mozne zavolat napriklad z triggra po inserte do tabulky. predpokladam, ze sa tato funkcia moze hodit viacerym z vas, preto sa s vami o nu rad podelim.
vychadzal som z tohoto:
http://www.postgresql.org/docs/8.4/static/plpython.htmlhttp://docs.python.org/library/email-examples.htmla tu je slubena funkcia, v najjednoduchsom vydani, mne ale plne postacuje:
--------------------------------------------------------------------------------
#DROP FUNCTION pymail (email_from varchar, email_to varchar, email_subject varchar, email_text varchar);
CREATE FUNCTION pymail (email_from varchar, email_to varchar, email_subject varchar, email_text varchar)
RETURNS integer
AS $$
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
msg = MIMEText(email_text)
msg['Subject'] = email_subject
msg['From'] = email_from
msg['To'] = email_to
# Send the message via our own SMTP server, but don't include the envelope header
s = smtplib.SMTP('localhost')
s.sendmail(msg['From'], msg['To'], msg.as_string())
s.quit()
return 0
$$ LANGUAGE plpythonu;
--------------------------------------------------------------------------------