Online Shopping : Computers : Programming : Languages : Perl

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

44 of 61 people (72%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How to attach a file to a mail with sendmai or other ?
Besides using a module eg. Mail::Sender, can I use the server's sendmail program to attach files? An

Jun 16th, 2000 07:49
Marco Steinacher, Kirederf, Nazar Wahab, http://cpan.valueclick.com/modules/by-category/19_Mail_and_Usenet_News/Mail/


You can do this with the Module Mail::Sender.
You can get the Module Mail::Sender at CPAN (see sources), if it isn't 
installed on your system yet.
You can view the documenation with "perldoc Mail::Sender".
Example:
********
# This example will send the file "/tmp/somefile.vbs" to 
# [email protected] and a copy to [email protected] and
# [email protected] with the subject "A file for my friends"
# and the message-body "Hello friends.\n\nPlease open this file.\n",
# using the SMTP-Host smtp.websource.ch and the From-Adress
# '[email protected] (WebSource - Sales)'.
use Mail::Sender;
# Prepare Mailer
$sender = new Mail::Sender
	{smtp => 'smtp.websource.ch', from => '[email protected] 
(WebSource - Sales)'};
$err = $Mail::Sender::Error;
if ($err) die $err; # Terminate on error.
# Prepare message
$sendto="[email protected]";
$copys="[email protected],[email protected]";
$subject="A file for my friends";
$message="Hello friends.\n\nPlease open this file\n";
$file="/tmp/somefile.vbs";
# Send the mail
$sender->MailFile({to => $sendto,
		cc => $copys,
		subject => $subject,
		msg => $message,
		file => $file});
$err = $Mail::Sender::Error;
if ($err) die $err; # Terminate on error.