Pivotal Knowledge Base

Follow

How to send Mail in Greenplum using plperlu

Environment

  • Pivotal Greenplum Database (GPDB) 4.3.x
  • Operating System- Red Hat Enterprise Linux 6.x

Purpose

This article describes how to send mail to GPDB using plperlu.

Procedure

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