Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jX6Vo-0004Wg-FK for pgsql-general@arkaria.postgresql.org; Fri, 08 May 2020 17:10:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jX6Vn-0002Wj-Ao for pgsql-general@arkaria.postgresql.org; Fri, 08 May 2020 17:10:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jX6Vn-0002Wc-0u for pgsql-general@lists.postgresql.org; Fri, 08 May 2020 17:10:11 +0000 Received: from athena.simkin.ca ([2607:f040:1001:2::ff:2]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jX6Vg-0001Nv-N5 for pgsql-general@lists.postgresql.org; Fri, 08 May 2020 17:10:10 +0000 Received: from skynet.simkin.ca (d205-250-70-177.bchsia.telus.net [205.250.70.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by athena.simkin.ca (Postfix) with ESMTPSA id 4249BDC69707 for ; Fri, 8 May 2020 10:10:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.simkin.ca; s=athena; t=1588957803; bh=jeFamuP4AEBiNNM+PaHfYS8ebrao7oGN8l65lA/OAxA=; h=Subject:From:To:Date:From:To:Subject:Date:Reply-To; b=btRfOu1rlyk/VJQzOXRgPNKIGOWm5F4ev48iOQ22qvvzCZgKuYuq1YKzQls9Ol+td vD4JIdj9FPOgtNy51O+Zu143qmYsboVMAtlJCtymmpR1M7rhIlQ5lfi/nPGIHACpCe y0PSLQCT988bPiYYGV5mlgU5MbLfdGvFbC+AuAjRPOH7DVCjcFHKl2UCjdZUO1X/KG 7ruXi06VwZWEUAyUH47HsXt+w4HFg1JGtsuHzBrdKlI8DiFiwdfUbAlgfhtfbTTCmZ ftZtDN6Jg9wj8yB+3wT6SIZeTvHsBDDI53OH28CPrTijVGdaYyfNa+81afUeDZJRI7 FUw9GmR2O+xyw== Received: from skynet.simkin.ca (skynet.simkin.ca [IPv6:::1]) by skynet.simkin.ca (Postfix) with ESMTP id 173F8105B1B00 for ; Fri, 8 May 2020 10:10:02 -0700 (PDT) Message-ID: <2ca625f832b4ea49c99c99d559a086441db97768.camel@lists.simkin.ca> Subject: Re: Best way to use trigger to email a report ? From: Alan Hodgson To: pgsql-general@lists.postgresql.org Date: Fri, 08 May 2020 10:10:02 -0700 In-Reply-To: References: Content-Type: multipart/alternative; boundary="=-FM9+IMmbTx82ypwzEalh" X-PGP-Key: fp="EF82 6F8D A3BA A096 FFA3 05F2 A7A0 40A5 34E5 AA0B"; id="0x34E5AA0B"; get= User-Agent: Evolution 3.34.4 MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=-FM9+IMmbTx82ypwzEalh Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit On Fri, 2020-05-08 at 12:26 -0400, David Gauthier wrote: > psql (9.6.0, server 11.3) on linux > > Looking for ideas. I want a trigger to... > 1) compose an html report based on DB content > 2) email the report to a dist list (dl = value of a table column) > > If this will involve hybrid coding, I prefer PL/perl. The linux env > has both "mail" and "mutt" (if this is of any help). > plperlu can access resources outside PostgreSQL. I'd suggest using Net::Mail and Net::SMTP to compose and send the mail to localhost:25. This avoids any shell escaping issues and still lets your local MTA accept the mail immediately and deliver it when it can. --=-FM9+IMmbTx82ypwzEalh Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: quoted-printable
On Fri, 2020-05-08 at 12:26 -0400, David Gauthier wrote:
psql (9.6.0, server 11.3) on linux
=

Looking for ideas.  I want a trigger to...
1) compose an html= report based on DB content
2) email the report to a dist list (dl =3D val= ue of a table column)

If this will involve hybrid coding, I prefer P= L/perl.  The linux env has both "mail" and "mutt" (if this is of any h= elp).  


plperlu= can access resources outside PostgreSQL.

I'd sugg= est using Net::Mail and Net::SMTP to compose and send the mail to localhost= :25. This avoids any shell escaping issues and still lets your local MTA ac= cept the mail immediately and deliver it when it can.
--=-FM9+IMmbTx82ypwzEalh--