Pivotal Knowledge Base

Follow

How to send mail in Greenplum using plperlu

Environment

Product Version
Pivotal Greenplum (GPDB) 4.3.x
OS RHEL 6.x

Purpose

How to send mail in GPDB using plperlu?

Resolution

Follow these steps:

  1. Start the sendmail service on OS by running the following command
    /etc/rc.d/init.d/sendmail start
  2. Configure proper DNS server in below file to make sure that the domain name of target email address can be resolved.
    /etc/resolv.conf
  3. Create the following sample function to send mail.
    Create or replace function sendmail() returns integer as
    '
     #!/usr/bin/perl
      use Net::SMTP;
      my ($sendTo,$sendFrom, $Subject, $Message)=(''Target.Email@xxx.com'',''Source.Email@xxx.com'', ''Hello Subject'',''Hello Message'');
      my $smtp=Net::SMTP->new("localhost");
      $smtp->mail($sendFrom);
      $smtp->recipient($sendTo);
      $smtp->data();
      $smtp->datasend("To: $sendTo\n");
      $smtp->datasend("Subject: $Subject\n");
      $smtp->datasend("Content-Type: text/plain;\n\n");
      $smtp->datasend("$Message\n");
      $smtp->dataend();
      $smtp->quit();
      return 1;
    '
    language 'plperlu';
  4. Test this function and make sure the test email is received.
    select sendmail();
     sendmail
    ----------
            1

Comments

Powered by Zendesk