<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title># rm-rf.es &#187; mime::lite</title>
	<atom:link href="http://rm-rf.es/sobre/mimelite/feed/" rel="self" type="application/rss+xml" />
	<link>http://rm-rf.es</link>
	<description>Administración de sistemas, Unix, Linux, FreeBSD, Windows, hosting, dominios, servidores...</description>
	<lastBuildDate>Sat, 28 Jan 2012 19:36:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Perl: Enviar correos con el módulo MIME::Lite</title>
		<link>http://rm-rf.es/perl-enviar-correos-modulo-mimelite/</link>
		<comments>http://rm-rf.es/perl-enviar-correos-modulo-mimelite/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 20:16:12 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[correo]]></category>
		<category><![CDATA[mime::lite]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://rm-rf.es/?p=1032</guid>
		<description><![CDATA[Hoy vamos a ver un ejemplo sencillo de programación en Perl, mediante el cual vamos a enviar un correo electrónico. Utilizamos el módulo MIME::Lite, que permite mandar contenido html (u otro MIME) en el cuerpo del mensaje. El ejemplo que os voy a mostrar envía el correo utilizando el método de envío por defecto que [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy vamos a ver un ejemplo sencillo de programación en Perl, mediante el cual vamos a enviar un correo electrónico. Utilizamos el módulo <strong>MIME::Lite</strong>, que permite mandar contenido html (u otro MIME) en el cuerpo del mensaje.</p>
<p>El ejemplo que os voy a mostrar envía el correo utilizando el método de envío por defecto que tenga el sistema en el que se ejecuta (si es Linux, normalmente sendmail). Ahí va:</p>
<div class="codecolorer-container perl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span><br />
<span style="color: #000000; font-weight: bold;">use</span> MIME<span style="color: #339933;">::</span><span style="color: #006600;">Lite</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Asunto del correo&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$from</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;test<span style="color: #000099; font-weight: bold;">\@</span>dominio.com&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$to</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;destinatario<span style="color: #000099; font-weight: bold;">\@</span>dominio.com&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$body</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;Esto es el cuerpo del correo ...&quot;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$msg</span> <span style="color: #339933;">=</span> MIME<span style="color: #339933;">::</span><span style="color: #006600;">Lite</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Subject <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$subject</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; From &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$from</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; To &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$to</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Type &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'text/html'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Data &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">$body</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>&nbsp; <br />
<span style="color: #0000ff;">$msg</span><span style="color: #339933;">-&gt;</span><a href="http://perldoc.perl.org/functions/send.html"><span style="color: #000066;">send</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Básicamente declaramos las variables que contienen el asunto, destinatarios, cuerpo del mensaje, etc y abrimos la clase para trabajar con ella, finalmente enviamos el correo.</p>
<p>En la propia página de cpan hay bastantes ejemplos y muy útiles, os dejo un par de ellos, <a href="http://search.cpan.org/dist/MIME-Lite/lib/MIME/Lite.pm#field_order">podéis ver los demás aquí</a>.</p>
<p>Agregar una imagen a un mensaje con varios destinatarios:</p>
<div class="codecolorer-container perl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">### Start with a simple text message:</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">$msg</span> <span style="color: #339933;">=</span> MIME<span style="color: #339933;">::</span><span style="color: #006600;">Lite</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; From &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'me@myhost.com'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; To &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'you@yourhost.com'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Cc &nbsp; &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'some@other.com, some@more.com'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Subject <span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'A message with 2 parts...'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Type &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'TEXT'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Data &nbsp; &nbsp;<span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">&quot;Here's the GIF file you wanted&quot;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">### Attach a part... the make the message a multipart automatically:</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">$msg</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">attach</span><span style="color: #009900;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Type &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'image/gif'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Path &nbsp; &nbsp; <span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'aaa000123.gif'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Filename <span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'logo.gif'</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Utilizar otro método de envío de correo si no tenemos sendmail:</p>
<div class="codecolorer-container perl default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">### Do something like this in your 'main':</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$I_DONT_HAVE_SENDMAIL</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;MIME<span style="color: #339933;">::</span><span style="color: #006600;">Lite</span><span style="color: #339933;">-&gt;</span><a href="http://perldoc.perl.org/functions/send.html"><span style="color: #000066;">send</span></a><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'smtp'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$host</span><span style="color: #339933;">,</span> Timeout<span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">60</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AuthUser<span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">$user</span><span style="color: #339933;">,</span> AuthPass<span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">$pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">### Now this will do the right thing:</span><br />
&nbsp; &nbsp; <span style="color: #0000ff;">$msg</span><span style="color: #339933;">-&gt;</span><a href="http://perldoc.perl.org/functions/send.html"><span style="color: #000066;">send</span></a><span style="color: #339933;">;</span> &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">### will now use Net::SMTP as shown above</span></div></div>
<h4  class="related_post_title">También te puede interesar:</h4><ul class="related_post"><li><a href="http://rm-rf.es/db_file-xs101-db-h-no-such-file-or-directory/" title="DB_File.xs:101: db.h: No such file or directory">DB_File.xs:101: db.h: No such file or directory</a></li><li><a href="http://rm-rf.es/elegir-el-compilador-correcto-para-perl-en-solaris/" title="Elegir el compilador correcto para Perl en Solaris">Elegir el compilador correcto para Perl en Solaris</a></li><li><a href="http://rm-rf.es/exim-establecer-filtros-anti-spam-para-entrada-y-salida-de-correo/" title="Exim: establecer filtros anti-spam para entrada y salida de correo">Exim: establecer filtros anti-spam para entrada y salida de correo</a></li><li><a href="http://rm-rf.es/hmailserver-err-your-mailbox-is-already-locked/" title="hMailserver: ERR Your mailbox is already locked">hMailserver: ERR Your mailbox is already locked</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://rm-rf.es/perl-enviar-correos-modulo-mimelite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

