Re: the feasibility of sending email from stored procedure in Postgres

From: "Christopher Browne" <cbbrowne(at)gmail(dot)com>
To: hewei <heweiweihe(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: the feasibility of sending email from stored procedure in Postgres
Date: 2008-02-15 14:31:59
Message-ID: d6d6637f0802150631h505931eby2aa7f75e9fe2d3d7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 2/14/08, hewei <heweiweihe(at)gmail(dot)com> wrote:
> Can send email from stored procedure in Postgres?

In principle, yes, using one of the "untrusted" stored function
languages. pl/perl, pl/sh, pl/python, and such.

I wouldn't do things that way...

I would instead queue messages (or suitable information about them) in
a table, and have a process outside PostgreSQL periodically poll for
them. There are several benefits to that approach:

1. You're not pushing error handling of email problems inside the
PostgreSQL back end. That could be rather risky.

2. You're not spawning an MTA connection every time you submit a
message. This could be rather expensive.

In contrast, the "poll a queue" approach lets something completely
external deal with email problems. And it should be able to submit
multiple messages more or less at once, which should improve
efficiency rather a lot; no need to open up sockets to port 25 a whole
bunch of times...
--
http://linuxfinances.info/info/linuxdistributions.html
"The definition of insanity is doing the same thing over and over and
expecting different results." -- assortedly attributed to Albert
Einstein, Benjamin Franklin, Rita Mae Brown, and Rudyard Kipling

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Phoenix Kiula 2008-02-15 14:36:20 Re: Are indexes blown?
Previous Message Tomás Di Doménico 2008-02-15 14:25:10 Re: Trying to understand encoding.