Invio mail
Come inviare mail tramite script perl
Esiste più di un modo per inviare mail da uno script perl. Descriviamo qui il più utilizzato.
Inviare mail mediante Sendmail
#!/usr/bin/perl
unless(open (MAIL, "|/usr/sbin/sendmail -t")) {
print "error.\n";
warn "Error starting sendmail: $!";
}
else{
print MAIL "From: me\@mydom.com\n";
print MAIL "To: test\@testdom.com\n";
print MAIL "Subject: test subject\n\n";
print MAIL "test mail message";
close(MAIL) || warn "Error closing mail: $!";
print "Mail sent.\n";
}
Ricordiamo che il destinatario può essere inserito direttamente quando viene richiamato il comando sendmail; lo script diventerà quindi:
#!/usr/bin/perl
unless(open (MAIL, "|/usr/sbin/sendmail recipient\@someplace.com")) {
print "error.\n";
warn "Error starting sendmail: $!";
}
else{
print MAIL "From: me\@mydom.com\n";
print MAIL "Subject: test subject\n\n";
print MAIL "test mail message";
close(MAIL) || warn "Error closing mail: $!";
print "Mail sent\n";
}Publication details
Category: Perl
Published by: loryzz on date: 06.01.2008 21:26:15
Last edit by: loryzz on date: 21.01.2009 11:27:37
Ratings
Leave a comment
All comments must be approved by site administrator.
Please write comments on topic. Spam will be never approved.
Perl: Linked articles
Hash ed array published by loryzz in Perl
























Ritorna all'inizio
Based total comments
0 %
Comments percentage
0 %