How to send Mail in Greenplum using plperlu
search cancel

How to send Mail in Greenplum using plperlu

book

Article ID: 296045

calendar_today

Updated On:

Products

VMware Tanzu Greenplum

Issue/Introduction

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

 


Environment


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)=(''[email protected]'',''[email protected]'', ''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


Additional Information

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