Envío de correo electrónico con Perl
Linux, Perl Diciembre 16th, 2007Función para enviar un correo electrónico con Perl:
PERL:
-
#!/usr/bin/perl -w
-
sub smtp {
-
-
use Email::MIME::Creator;
-
my ( $To, $FromName, $FromMail, $Bcc, $Subject, $msg_html ) = @_;
-
-
my @html = $msg_html;
-
-
# mensaje multipart
-
my @parts = (
-
Email::MIME->create(
-
attributes => {
-
content_type => "text/html; charset=iso-8859-1",
-
encoding => "quoted-printable",
-
},
-
body => "@html",
-
),
-
);
-
-
# Declaramos al sender y adjuntamos los archivos a enviar
-
my $email = Email::MIME->create(
-
header => [ From => "$FromName <$FromMail>" ],
-
parts => [ @parts ],
-
);
-
-
# modificamos nuestro encabezado
-
$email->header_set( "MIME-Version: 1.0\r\n" );
-
$email->header_set("Content-type: text/html; charset=iso-8859-1\r\n");
-
$email->header_set( 'X-PoweredBy' => 'v3.0' );
-
$email->header_set( To => "$To" );
-
$email->header_set( Bcc => "$Bcc" );
-
$email->header_set( Subject => "$Subject" );
-
-
# modificaciones avanzadas, elegimos base64 o bien 7bit para aceptar multipart
-
#$_->encoding_set( 'base64' ) for $email->parts;
-
-
# Accesamos al binario de sendmail y enviamos los mensajes
-
#open (MAIL, "|/usr/sbin/postfix") || die "No hay acceso al binario sendmail\n";
-
print MAIL $email->as_string;
-
}
Para usar la función:
PERL:
Tags: smtp | perl | envio | de | correo | funcion
-
&smtp($vTo, $vFromName, $vFromMail, $vBcc, $vSubject, $vmsg_html );


Diciembre 16th, 2007 at 7:57 pm
Vas a conseguir que acabe hechandole un vistazo a este lenguaje. Un saludo¡
Diciembre 16th, 2007 at 8:44 pm
^_^ a mi me gusta este lenguaje aunque profesionalmente no he tenido mucha ocasión de ponerlo en práctica. Salu2.