转帖:如何用Net::SMTP发送邮件

转载自::http://fayland.org/journal/NetSMTP.html

 

如何用Net::SMTP发送邮件

Category: Modules   Keywords: Net::SMTP mail

Code

如下代码为用163.com的SMTP来发送邮件。
#!/usr/bin/perl
use Net::SMTP;
my $mailhost = "smtp.163.com"; # the smtp host
my $mailfrom = '[email protected]'; # your email address
my @mailto = ('[email protected]', '[email protected]'); # the recipient list
my $subject = "此为标题";
my $text = "此为正文\n第二行位于此。";
$smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout => 120, Debug => 1);
# anth login, type your user name and password here
$smtp->auth('user','pass');
foreach my $mailto (@mailto) {
	# Send the From and Recipient for the mail servers that require it
	$smtp->mail($mailfrom);
	$smtp->to($mailto);
	# Start the mail
	$smtp->data();
	# Send the header
	$smtp->datasend("To: $mailto\n");
	$smtp->datasend("From: $mailfrom\n");
	$smtp->datasend("Subject: $subject\n");
	$smtp->datasend("\n");
	# Send the message
	$smtp->datasend("$text\n\n");
	# Send the termination string
	$smtp->dataend();
}
$smtp->quit;

你可能感兴趣的:(职场,perl,smtp,休闲)