0

I have the following code to send emails and wanted to see if it's possible to attach a csv file?

CREATE OR REPLACE FUNCTION public.send_email_html(text, text, text, text)
 RETURNS integer
 LANGUAGE plperlu
AS $function$
    use Net::SMTP;

    my ($recipientString, $sendFrom, $subject, $message) = @_;
    my @recipients = split /;/, $recipientString;
    my $smtp=Net::SMTP->new("localhost");
    
    $smtp->mail($sendFrom);
    foreach(@recipients)
    {
        $smtp->recipient($_);
    }
    $smtp->data();
    foreach(@recipients)
    {
        $smtp->datasend("To: $_\n");
    }
    
    $smtp->datasend("Subject: $subject\n");
    $smtp->datasend("Content-Type: text/html;\n");
    $smtp->datasend("$message\n");
    $smtp->quit();

    return 1;
$function$
;
0

Since you've already picked perl the easiest way might be to use MIME::Lite

| improve this answer | |
  • That's a good idea, however I may not be able to install this on a production server.. – Matias Aug 10 at 22:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.