Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I ve got this subroutine which sends out mail from my script:

sub sendemail { my ($to,$from,$subject,$message) = @_; my $trash; if ($config{'mailhost'}) { eval('use IO::Socket; 1;') or &oops("IO::Socket could not be l +oaded by the script. Please see the script documentation for details +. It looks like this server is using perl version $]. IO::Socket ma +y not be included with versions of perl prior to 5.00404."); # don't +cause errors on machines where IO::Socket is not available my $remote; $remote = IO::Socket::INET->new("$config{'mailhost'}:s +mtp(25)"); $remote->autoflush(); print $remote "HELLO\r\n"; $trash = <$remote>; print $remote "MAIL From:<$config{'admin_address'}>\r\ +n"; $trash = <$remote>; print $remote "RCPT To:<$to>\r\n"; $trash = <$remote>; print $remote "DATA\r\n"; $trash = <$remote>; print $remote "From: <$from>\r\nSubject: $subject\r\n\ +r\n"; print $remote $message; print $remote "\r\n.\r\n"; $trash = <$remote>; print $remote "QUIT\r\n"; } else { open MAIL, "|$config{'mailprog'}"; print MAIL "To: $to\nFrom: $from\nSubject: $subject\n\ +n$message\n\n"; close MAIL; } }

I use this line of code to call the subroutine:

&sendemail($Recipient_Email,$Admin_Address,"$Email_Body");

My Question is: What line of code and where do I need to add it in order to send out an attached file, (Email_Template.html), replacing the texted $Email_Body.

Thanx beforehand: VirtualWeb.

Replies are listed 'Best First'.
Re: Email a File from Code
by Corion (Patriarch) on Sep 29, 2008 at 13:15 UTC

    Instead of talking to the mail server yourself, I recommend using MIME::Lite for sending mails and attaching files. The documentation also has lots of examples.

Re: Email a File from Code
by Anonymous Monk on Sep 29, 2008 at 13:21 UTC
    My Question is: What line of code and where do I need to add it in order to send out an attached file, (Email_Template.html), replacing the texted $Email_Body.
    Don't! You really don't want to learn MIME or SMTP.
    Switch to Email::Simple (part of Perl Email Project)
Re: Email a File from Code
by lamp (Chaplain) on Sep 29, 2008 at 15:33 UTC
Re: Email a File from Code
by rovf (Priest) on Sep 30, 2008 at 08:12 UTC

    I use Mail::SendEasy for sending mail with attachments. So far, I'm happy with it.

    -- 
    Ronald Fischer <ynnor@mm.st>