attach csv file on email sent from postgres

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: $subjectn");
    $smtp->datasend("Content-Type: text/html;n");
    $smtp->datasend("$messagen");
    $smtp->quit();

    return 1;
$function$
;

Go to Source
Author: Matias