Thursday, May 8, 2014

How to send email in Greenplum using plperl

Wanna send emails using a function in Greenplum?
Here you are.

1. Start sendmail service

/etc/rc.d/init.d/sendmail start

2. Configure proper DNS server to ensure that the domain name of target email address can be resolved.

3. This is a sample function for send mail
create or replace function sendmail() returns integer as
  use Net::SMTP;
  my ($sendTo,$sendFrom, $Subject, $Message)=('''','''', ''Hello from OpenKB'',''Hello:)'');
  my $smtp=Net::SMTP->new("localhost");
  $smtp->datasend("To: $sendTo\n");
  $smtp->datasend("Subject: $Subject\n");
  $smtp->datasend("Content-Type: text/plain;\n\n");
  return 1;
language 'plperlu';
openkb=# select sendmail();
(1 row)

No comments:

Post a Comment

Popular Posts