Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Answer: How do I send an email with Perl (including an attachment)?

by fongsaiyuk (Pilgrim)
on Dec 06, 2000 at 19:29 UTC ( #45225=categorized answer: print w/replies, xml ) Need Help??

Q&A > mail and news > How do I send an email with Perl (including an attachment)? - Answer contributed by fongsaiyuk

I use Mail::Sender pretty extensively. Here's a code snippet to get you started for sending an email with an attachment. (We let the user's email client determine the helper application to execute based on the file extension of the filename we attach to the message.)

Mail::Sender lets you customize the MIME stuff, but for simple single files you don't need to do that.

sub send_email { my $sender = new Mail::Sender({ from => $from_address, }); $sender->OpenMultipart({ to => $to_email, subject => $subject, }); $sender->Body; $sender->SendLine( $msg_body ); $sender->SendFile({ description => 'Raw Data File', encoding => '7BIT', file => $tempfile, }); $sender->Close; }

I really like this module. You should seriously consider installing it if you find that you are doing a lot with emailing attachments. It has saved me tons of time.

  • Comment on Answer: How do I send an email with Perl (including an attachment)?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[karlgoethebier]: good #metoo
LanX too #metoo
Discipulus 2 #metoo

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2018-02-20 10:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (270 votes). Check out past polls.

    Notices?