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

Re: [MacPerl] SMTP





Floyd Resler wrote:
> 
> Hello,
>     How can I specify the subject of an email I am sending using the
> Net::SMTP.pm module?
----------------

its not explicitly in the documentation (
http://www.perldoc.com/perl5.6/lib/Net/SMTP.html ), but you can put in
whatever you want for To, From, Subject, and Date in the data section of
the mail. The To and From used in the header are independent of what
shows up.... this is how stuff gets forged many times.


here is an example:

#!/usr/bin/perl -w

=head1 test Net::SMTP

	Notes:
	- couldnt see any way to attach files or images without jumping thru
	  hoops to encode data and manually add headers.
	- cant send to multiple addresses as documented; probably not a good
idea
	anyway as docs indicate that mail will fail if one address is bad.
	- verify() method is "locally disabled"... too bad, cant check
addresses

=cut
    
use Net::SMTP;

$smtp = Net::SMTP->new('mail',		# connect to an SMTP server
                                Hello => 'mail' ,
                                Timeout => 30,
                                Debug   => 0,
                               );

print "domain=".$smtp->domain." \n";

$smtp->mail( 'you@yourdomain.com' );     	# use the sender's address
here
$smtp->to( 'someone@realplace.com' );       	# recipient's address

$smtp->data();                      		# Start the mail

# Send the header.
$smtp->datasend("To: testman<".'nobody@doesntmatter.com'.">\n"); 	# can
be anything
$smtp->datasend("From: someone\@here.com\n"); 				# can be anything
$smtp->datasend("Subject: email from perl\n");
$smtp->datasend("\n");

# Send the body.
my $TimeSent = scalar(localtime);
$smtp->datasend( "Hello, World! \n");
$smtp->datasend( "composed: $TimeSent \n");
$smtp->dataend();                   # Finish sending the mail
$smtp->quit;                        # Close the SMTP connection


print "\n\n--- done --- \n\n" ; sleep 1;
# -----------------------------------------------------------
1;

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