Sending Content of URL via sendMail

32 views
Skip to first unread message

Redsmeg68

unread,
Sep 2, 2020, 8:58:14 PM9/2/20
to Perl Mail::Sendmail

I have a legacy app that needs to change. it is written in perl and uses send::mail to send mails to users. Previously we sent links in the email message body but now they want pdf attachments instead. The PDF's are generated on another server using php.

the workflow would be

  1. create the email body
  2. get the pdf from another server via a URL
  3. add the pdf as an attachment to the email
  4. send it.

I can use 

LWP::Simple; 
unless (defined ($content = get $URL)) { 
        die "could not get $URL\n";
}

to get the contents of the URL but I can't figure out how to use that var as an attachment in sendmail. current sendmail code is:

my %maildata = (
     To => $to, From => 'OurSite - Billing <bil...@ourSite.com>',
     Organization => 'OurSite, LLC http://www.OurSite.com/', 
     Bcc => 'sentb...@ourSite.com', 
     Subject => $subject{$message} || 'ourSite invoice', Message => $body 
);
sendmail(%maildata) || print STDERR $Mail::Sendmail::error;

I know I could set the content-type and the attachment: filename but that assumes storing the returned URL prior to attempting to send and I wasn't intending to do that.


Reply all
Reply to author
Forward
0 new messages