Invio mail

Come inviare mail tramite script perl

Invio mail

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

Statistics

Details  This article has been viewed 2.201 times.

Send to

add to digg add to reddit add to furl add to facebook add to delicious add to google add to stumbleupon add to technorati add to ask add to live

Ratings

  • Currently 0; ?>/ TOTALSTARS
  • 1
  • 2
  • 3
  • 4
  • 5

Comments

Details 0 user comments, 0 still waiting.

Leave a comment

All comments must be approved by site administrator.
Please write comments on topic. Spam will be never approved.


Confirmation code

Please take a look to image and insert character into the form field.

Perl: Linked articles