Re: Need psql send email

Поиск
Список
Период
Сортировка
От Martin Gainty
Тема Re: Need psql send email
Дата
Msg-id BLU142-W2536C633871660098FE7F2AE9A0@phx.gbl
обсуждение исходный текст
Ответ на Re: Need psql send email  (Martin French <Martin.French@romaxtech.com>)
Ответы Re: Need psql send email  (Chris Travers <chris.travers@gmail.com>)
Список pgsql-general
many is the time when spammers have used Open Relay SMTP servers to send their junk mail so i would advise against using sendmail on Open Relay SMTP servers
I would narrow access by SSH or open a secure tunnel thru your firewall to your own internal DatabaseManagementSystem/J2EEServer/ApacheHTTPServer then allow
those scripts (PL-SQL or Perl or Java) to invoke sendmail to the SMTPMailServer inside the firewall

If you are sponsoring your own email-server and I hope you are DISALLOW OPEN RELAY
Martin Gainty
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




To: depesz@depesz.com
CC: pavithra.ibt@gmail.com; pgsql-general@postgresql.org; pgsql-general-owner@postgresql.org
Subject: Re: [GENERAL] Need psql send email
From: Martin.French@romaxtech.com
Date: Thu, 20 Sep 2012 13:40:58 +0100


> > Hi All,I am new to postgresql. I want to send email by using pl
> pgsql. I want
> > to know how to set up the configurations for mail server.Can any one help me
> > in solving this?. pavithra.ibt@gmail.com
>
>
http://www.depesz.com/2012/06/13/how-to-send-mail-from-database/
>
> Best regards,
>
> depesz

Alternatively:


CREATE OR REPLACE FUNCTION sendmail(p_from text, p_to text, p_subject text, p_content text)
  RETURNS void AS
$BODY$
use strict;
use warnings;
my ($from, $to, $subject, $content) = @_;
 
open(MAIL, "|/usr/sbin/sendmail -t") or die 'Cannot send mail';
print MAIL "From: $from\n";
print MAIL "To: $to\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$content";
 
close(MAIL);
$BODY$
  LANGUAGE plperlu;


Works ok provided sendmail is configured.

or:

CREATE OR REPLACE FUNCTION send_smtp(p_mail_host text,
                                        p_from text,
                                        p_to text,
                                        p_subject text,
                                        p_content text,
                                        p_timeout integer DEFAULT 60,
                                        p_debug integer DEFAULT 0,
                                        p_exactaddr integer DEFAULT 1,
                                        p_skipbad integer DEFAULT 1)
  RETURNS void AS
$BODY$
use strict;
use warnings;
use Net::SMTP;
no strict 'refs';

my ($host, $sender, $recipient, $subject, $body, $timeout, $debug, $exact, $skipbad) = @_;
(!defined($host) || !($host)) && die 'No SMTP host provided.';
(!defined($sender) || !($sender)) &&  die 'No sender address/name provided.';
(!defined($recipient) || !($recipient)) &&  die 'No recipient address specified.';

my $mail = Net::SMTP->new(
                                Host => $host,
                                Debug => $debug,
                                Timeout => $timeout,
                                ExactAddresses => $exact
                        ) or die 'Net::SMTP->new() Failed';

$mail->mail($sender);
$mail->recipient($recipient, { SkipBad => $skipbad });

$mail->data();
$mail->datasend("MIME-Version: 1.0\n");
$mail->datasend("From:" . $sender . "\n");
$mail->datasend("To:" . $recipient . "\n");
$mail->datasend("Reply-To: ". $sender . "\n");
$mail->datasend("Subject:" . $subject . "\n\n");
$mail->dataend();
$mail->quit();
$BODY$
  LANGUAGE plperlu;


Feel free to hack away as much as required.

Both of these work fine provided PL/PerlU is installed and the server is properly configured on the network, and that there is a valid SMTP mail host to receive.


Cheers

Martin

=============================================

Romax Technology Limited
Rutherford House
Nottingham Science & Technology Park
Nottingham,
NG7 2PZ
England

Telephone numbers:
+44 (0)115 951 88 00 (main)

For other office locations see:
http://www.romaxtech.com/Contact
=================================
===============
E-mail: info@romaxtech.com
Website:
www.romaxtech.com
=================================

================
Confidentiality Statement
This transmission is for the addressee only and contains information that is confidential and privileged.
Unless you are the named addressee, or authorised to receive it on behalf of the addressee
you may not copy or use it, or disclose it to anyone else.
If you have received this transmission in error please delete from your system and contact the sender. Thank you for your cooperation.
=================================================

В списке pgsql-general по дате отправления:

Предыдущее
От: Craig Ringer
Дата:
Сообщение: Re: Need psql send email
Следующее
От: Edson Richter
Дата:
Сообщение: Re: Slow counting still true?