SPUG: Send email from XP

Orr, Chuck (NOC) CO4004 at att.com
Wed Jun 4 17:15:57 PDT 2008


Hey Ron,

     I like MIME::Lite with Net::SMTP.  MIME::Lite allows you to work
with attachments.
     Here is an example, it is based on the CPAN docs, I don't remember
for sure where I obtained that mime types URL, though.  It does work on
my XP box as of this afternoon.

#!/bin/perl -w

use MIME::Lite;
use Net::SMTP;


my $from_address = 'randomperson at randomplace.com';
my $to_address   = 'spug at magnadev.com';

# THIS IS THE SMTP SERVER
my $mail_host    = 'YOUR Mailhost here';

my $subject      = 'attachment test';
my $message_body = "Here is the attachment you asked about";

my $file         = 'Name of file you would like to attach';

# Create multipart container

$msg = MIME::Lite->new (
   From    => $from_address,
   To      => $to_address,
   Subject => $subject,
   Type    => 'multipart/mixed'
   ) or die "Problem with multipart container creation: $!\n";

# Add Message part
   
$msg->attach (
   Type => 'TEXT',
   Data => $message_body
   ) or die "Problem with Message Part: $!\n";


#Add attachment
#MIME TYPES CAN BE FOUND HERE:
http://www.iana.org/assignments/media-types/index.html

$msg->attach (
   Type        => 'text/plain',
   Path        => "$file", 
   Filename    => "$file",
   Disposition => 'attachment'
   ) or die "Problem with FILE ATTACHMENT: $!\n";

#Send the Message

  MIME::Lite->send('smtp', $mail_host, Timeout=>60, Debug=>2,
                   AuthUser=>'yourmailuser',
AuthPass=>'yourmailpassword'); 
  $msg->send;

  
I hope this helps,
Chuck



More information about the spug-list mailing list