[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Problems with SMTP sending an email message



> Here is a program I copied from MPPE to send email.  I'm having trouble
> with it because after I ran it once, my Mac froze up. 

Shame on you, Charles!  You modified the program when you "copied" it! 
;-) I can testify that the unmodified version works as advertised.

The script (Chapter 17, pg. 242) uses Mac::InternetConfig instead of 
specifying a new host in SMTP.pm's new() method.  Your version leaves out 
Mac::InternetConfig, and thus doesn't specify a SMTP host at all that I 
can see.  Also you've taken the array '@emails' and placed it in 
double-quotes when it isn't needed (no variables to interpolate), and it 
forces you to escape the '@' in the string.

You shouldn't have had to re-install Config.pm, or SMTP.pm as they're 
part of the standard MacPerl distro.  In fact, you shouldn't replace 
modules from the standard distro unless you REALLY know what you're 
doing.  Take a look at how this differs (I've added some comments, but 
otherwise this is practically straight out of the book):

#!perl
use strict;
use Net:SMTP;
use Mac::InternetConfig;
my($smtp, $email, @emails, $subject, $message);

$smtp    = Net::SMTP->new();
$email   = $InternetConfig{kICEmail()}; # grab my email from 
InternetConfig
@emails  = 'someone@some.domain';       # single quotes (no 
interpolation!)
$subject = "Subject: test message\n\n"; # doubles (interpolate newlines!)
$message = <<EOM;
Sorta like so, eh?
EOM

$smtp->mail($email)       or warn('failure 1');
$smtp->to(@emails)        or warn('failure 2');
$smtp->data()             or warn('failure 3');
$smtp->datasend($subject) or warn('failure 4');
$smtp->datasend($message) or warn('failure 5');
$smtp->dataend()          or warn('failure 6');
$smtp->quit()             or warn('failure 7');

__END__

This is one of the first things I played around with when working my way 
through MPPE, so I'm fairly clear on how it works.

--B

# Fungal Parataxonomy                   Mycology Information (Mycoinfo)
# Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
# <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
#
# First they ignore you. Then they laugh at you. Then they fight you.
# Then you win.                                     --Mohandas Gandhi


===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org