<?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>wd and cc &#187; sendmail</title>
	<atom:link href="http://wdicc.com/tag/sendmail/feed/" rel="self" type="application/rss+xml" />
	<link>http://wdicc.com</link>
	<description>Happy every day...</description>
	<lastBuildDate>Mon, 06 Sep 2010 10:00:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>无聊又写一个用来发邮件的 pm..</title>
		<link>http://wdicc.com/sendmail-pm/</link>
		<comments>http://wdicc.com/sendmail-pm/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 08:23:35 +0000</pubDate>
		<dc:creator>wd</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://wdicc.com/sendmail-pm/</guid>
		<description><![CDATA[继使用 perl 发中文标题邮件，和中文附件邮件后，又把他们整合了一下写了一个 pm 干这个事。 其实发带附件的邮件应该是有现成的 pm 干这个事的，比如 MIME::Lite 之类，没特殊需求还是用那个... ]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-9015557074547192";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "image";
//2007-06-17: index
google_ad_channel = "2704127095";
google_color_border = "660000";
google_color_bg = "FFFFFF";
google_color_link = "CC0000";
google_color_text = "000000";
google_color_url = "0066CC";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></-> <p>继使用 perl 发<a href='http://wdicc.com/sendmail-use-perl/'>中文标题邮件</a>，和<a href='http://wdicc.com/sned-mail-with-attachment/'>中文附件邮件</a>后，又把他们整合了一下写了一个 pm 干这个事。</p>
<p>其实发带附件的邮件应该是有现成的 pm 干这个事的，比如 MIME::Lite 之类，没特殊需求还是用那个吧，这个纯属无聊写的。</p>
<p>文件前面有使用方法。。</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000066;">package</span> SendMail<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> warnings<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Data<span style="color: #339933;">::</span><span style="color: #006600;">Dumper</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Encode<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> MIME<span style="color: #339933;">::</span><span style="color: #006600;">Base64</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">=head1 Examples
use SendMail;
&nbsp;
my $sm = SendMail-&gt;new( {
    To =&gt; 'you@foo.com, other@bar.com',
    Subject =&gt; 'just a test 中文',
    });
&nbsp;
-- or --
&nbsp;
my $sm = SendMail-&gt;new( {
    From =&gt; 'me@abc.com',
    To =&gt; 'you@foo.com, other@bar.com',
    Subject =&gt; 'just a test 中文',
    } );
&nbsp;
-- or --
&nbsp;
my $sm = SendMail-&gt;new( {
    From =&gt; 'me@abc.com',
    To =&gt; 'you@foo.com, other@bar.com',
    Cc =&gt; 'cc@foobar.com',
    Subject =&gt; 'just a test 中文',
    } );
&nbsp;
&nbsp;
$sm-&gt;attach( {
    Type =&gt; &quot;text/plain&quot;,
    Data =&gt; &quot;只是一个测试..a test&quot;
    });
&nbsp;
$sm-&gt;attach( {
    Type =&gt; 'application/octet-stream',
    Filename =&gt; 'test 中文.txt',
    Data =&gt; &quot;只是一个 test ...&quot;
    });
&nbsp;
$sm-&gt;test;
&nbsp;
-- or --
&nbsp;
$sm-&gt;send;
&nbsp;
=cut</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> vars <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$VERSION</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$VERSION</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'0.01'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$boundary</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;FFFFFFFFKKKKKK&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$from</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'no-reply@abc.com'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;No subject&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$to</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$cc</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">@body</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$package</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$info</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #0000ff;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$info</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Subject<span style="color: #009900;">&#125;</span> <span style="color: #339933;">||</span> <span style="color: #0000ff;">$subject</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$subject</span> <span style="color: #339933;">=</span> encode<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MIME-B'</span><span style="color: #339933;">,</span> decode<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'utf8'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$subject</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$info</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>From<span style="color: #009900;">&#125;</span> <span style="color: #339933;">||</span> <span style="color: #0000ff;">$from</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$info</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>To<span style="color: #009900;">&#125;</span> <span style="color: #339933;">||</span> <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Need to set MailTo 'To'!&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$cc</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$info</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Cc<span style="color: #009900;">&#125;</span> <span style="color: #339933;">||</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">push</span> <span style="color: #0000ff;">@body</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;MIME-Version: 1.0&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">push</span> <span style="color: #0000ff;">@body</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Content-Type: multipart/mixed; boundary=<span style="color: #000099; font-weight: bold;">\&quot;</span>$boundary<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">push</span> <span style="color: #0000ff;">@body</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">return</span> <span style="color: #000066;">bless</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$package</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> attach <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$f_hash</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">die</span> <span style="color: #ff0000;">&quot;Need data when attach!&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #b1b100;">not</span> <span style="color: #000066;">defined</span> <span style="color: #0000ff;">$f_hash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Data<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$type</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;text/plain&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$f_hash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Type<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">if</span> <span style="color: #000066;">defined</span> <span style="color: #0000ff;">$f_hash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Type<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@t</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">push</span> <span style="color: #0000ff;">@t</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;--$boundary&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$type</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">&quot;text/plain&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">push</span> <span style="color: #0000ff;">@t</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Content-Type: $type; charset=utf-8&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;file1.txt&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=</span> encode<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MIME-B'</span><span style="color: #339933;">,</span> decode<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'utf8'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$f_hash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Filename<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">if</span> <span style="color: #000066;">defined</span> <span style="color: #0000ff;">$f_hash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Filename<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">push</span> <span style="color: #0000ff;">@t</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Content-Type: $type&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">push</span> <span style="color: #0000ff;">@t</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Content-Disposition: attachment; filename=$filename&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">push</span> <span style="color: #0000ff;">@t</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;Content-Transfer-Encoding: base64&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">push</span> <span style="color: #0000ff;">@t</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">push</span> <span style="color: #0000ff;">@t</span><span style="color: #339933;">,</span> encode_base64<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$f_hash</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>Data<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">push</span> <span style="color: #0000ff;">@body</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@t</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #000066;">send</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fh</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'|/usr/sbin/sendmail -t'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">print_to</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> print_to <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fh</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">push</span> <span style="color: #0000ff;">@body</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;--$boundary--&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #ff0000;">&quot;From: $from<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #ff0000;">&quot;To: $to<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #ff0000;">&quot;Cc: $cc<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$cc</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #ff0000;">&quot;Subject: $subject<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">@body</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #ff0000;">&quot;$_<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> test <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$self</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">open</span> <span style="color: #009900;">&#40;</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fh</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'&gt;-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$self</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">print_to</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$fh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://wdicc.com/sendmail-pm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用 perl 发带附件的邮件</title>
		<link>http://wdicc.com/sned-mail-with-attachment/</link>
		<comments>http://wdicc.com/sned-mail-with-attachment/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 10:33:38 +0000</pubDate>
		<dc:creator>wd</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://wdicc.com/sned-mail-with-attachment/</guid>
		<description><![CDATA[继 上篇 使用 perl 发带中文标题的邮件后，又研究了下发带附件的。 基本差别不大，主要是那个 Content-type 要变一下。那个 boundary 可以自己随便写，和后面的统一就行了。 my $title = encode_base64&#4... ]]></description>
			<content:encoded><![CDATA[<p>继 <a href="http://wdicc.com/sendmail-use-perl/">上篇</a> 使用 perl 发带中文标题的邮件后，又研究了下发带附件的。</p>
<p>基本差别不大，主要是那个 Content-type 要变一下。那个 boundary 可以自己随便写，和后面的统一就行了。</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$title</span> <span style="color: #339933;">=</span> encode_base64<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;标题&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$body</span> <span style="color: #339933;">=</span> encode_base64<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;邮件正文&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$attach</span> <span style="color: #339933;">=</span> encode_base64<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;附件内容&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$filename</span> <span style="color: #339933;">=</span> encode<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'MIME-B'</span><span style="color: #339933;">,</span> decode<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'utf8'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;文件中文.txt&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>MAIL<span style="color: #339933;">,</span> <span style="color: #ff0000;">'|/usr/sbin/sendmail -t'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;From: test<span style="color: #000099; font-weight: bold;">\@</span>abs.com<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;To: test<span style="color: #000099; font-weight: bold;">\@</span>abs.com<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;Subject: =?UTF-8?B?$title?=<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;"># print MAIL &quot;Content-type: text/plain; charset=utf-8\r\n&quot;;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #cc0000; font-style: italic;">&lt;&lt;EOF;
Content-Type: multipart/mixed; boundary=\&quot;FFFFFFFFKKKKKK\&quot;
&nbsp;
--FFFFFFFFKKKKKK
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
&nbsp;
$body
--FFFFFFFFKKKKKK
Content-Type: application/octet-stream
Content-Disposition: attachment; filename=$filename.csv
Content-Transfer-Encoding: base64
&nbsp;
$attach
--FFFFFFFFKKKKKK--
EOF</span>
    <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span>MAIL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://wdicc.com/sned-mail-with-attachment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用 perl 发送中文邮件标题乱码</title>
		<link>http://wdicc.com/sendmail-use-perl/</link>
		<comments>http://wdicc.com/sendmail-use-perl/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 08:25:23 +0000</pubDate>
		<dc:creator>wd</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://wdicc.com/?p=758</guid>
		<description><![CDATA[代码如下面，解决乱码的方法是使用 base64 编码。 use MIME::Base64::Perl; &#160; open&#40;MAIL, '&#124;/usr/sbin/sendmail -t'&#41;; &#160; my $recver = 'wangdong@abc.com'; my $alertTitle = &#34;中文 asdfsdf sdfsdf sdf sdf s df sd fsd f ... ]]></description>
			<content:encoded><![CDATA[<p>代码如下面，解决乱码的方法是使用 base64 编码。</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> MIME<span style="color: #339933;">::</span><span style="color: #006600;">Base64</span><span style="color: #339933;">::</span><span style="color: #006600;">Perl</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span>MAIL<span style="color: #339933;">,</span> <span style="color: #ff0000;">'|/usr/sbin/sendmail -t'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$recver</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'wangdong@abc.com'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$alertTitle</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;中文 asdfsdf sdfsdf sdf sdf s df sd fsd f sd fsd f sdf sdf sdf&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$alertText</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;body &quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$encoded</span> <span style="color: #339933;">=</span> encode_base64<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$alertTitle</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;From: alert<span style="color: #000099; font-weight: bold;">\@</span>abc.com<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;To: $recver<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;Subject: =?UTF-8?B?&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$encoded</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;?=<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;MIME-Version: 1.0<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;Content-type: text/plain; charset=utf-8<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> MAIL <span style="color: #ff0000;">&quot;$alertText&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span>MAIL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>这里面 encode_base64 可以把文本做 base64 编码，要注意的是这个方法的第二个参数，是用来把编码结果进行格式化的，会每 76 个字符插入一个这个参数，默认是换行。</p>
<p>如果不是 utf8 的文本，那把里面的 utf8 改一下就好了。</p>
]]></content:encoded>
			<wfw:commentRss>http://wdicc.com/sendmail-use-perl/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>命令行发送有附件的邮件</title>
		<link>http://wdicc.com/send-mail-with-attachment/</link>
		<comments>http://wdicc.com/send-mail-with-attachment/#comments</comments>
		<pubDate>Mon, 01 Dec 2008 09:11:23 +0000</pubDate>
		<dc:creator>wd</dc:creator>
				<category><![CDATA[Mail]]></category>
		<category><![CDATA[sendmail]]></category>

		<guid isPermaLink="false">http://wdicc.com/?p=465</guid>
		<description><![CDATA[命令行下面发送邮件比较简单，恐怕都会使用。 $ echo &#34;hello .. &#34; &#124; mail -s subject xxx@abc.com $ cat /path/to/file &#124; mail -s subject xxx@abc.com $ mail -s subject xxx@abc.com &#60;&#60; EOF hi the end.. EOF 上面这... ]]></description>
			<content:encoded><![CDATA[<p>命令行下面发送邮件比较简单，恐怕都会使用。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;hello .. &quot;</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> subject xxx<span style="color: #000000; font-weight: bold;">@</span>abc.com
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> subject xxx<span style="color: #000000; font-weight: bold;">@</span>abc.com
$ mail <span style="color: #660033;">-s</span> subject xxx<span style="color: #000000; font-weight: bold;">@</span>abc.com <span style="color: #cc0000; font-style: italic;">&lt;&lt; EOF
hi
the end..
EOF</span></pre></div></div>

<p>上面这些方法都可以发送邮件。还有一种方法。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cat</span> a.txt
Subject: <span style="color: #7a0874; font-weight: bold;">test</span>
From: xxx<span style="color: #000000; font-weight: bold;">@</span>abc.com
To: xxx<span style="color: #000000; font-weight: bold;">@</span>abc.com
&nbsp;
hi
sdfsdfsdf
the end.
$ <span style="color: #c20cb9; font-weight: bold;">cat</span> a.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sendmail</span> <span style="color: #660033;">-t</span></pre></div></div>

<p>这样可以把邮件头信息写到文件里面的，你也可以用 php，perl 来打印类似的信息给 sendmail -t ，让他来发。</p>
<p>那么如果有附件应该怎么办？可以使用 uuencode。</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ uuencode a.txt a.txt <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #7a0874; font-weight: bold;">test</span> xxx<span style="color: #000000; font-weight: bold;">@</span>abc.com
$ <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> a.txt; uuencode b.txt b.txt; <span style="color: #c20cb9; font-weight: bold;">cat</span> c.txt<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sendmail</span> <span style="color: #660033;">-t</span></pre></div></div>

<p>应该说的很明白了吧？</p>
]]></content:encoded>
			<wfw:commentRss>http://wdicc.com/send-mail-with-attachment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sendmail 中自动抄送某个用户的邮件给别人</title>
		<link>http://wdicc.com/howto-cc-an-email-to-others-in-sendmail/</link>
		<comments>http://wdicc.com/howto-cc-an-email-to-others-in-sendmail/#comments</comments>
		<pubDate>Tue, 26 Jun 2007 03:20:01 +0000</pubDate>
		<dc:creator>wd</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mail]]></category>
		<category><![CDATA[sendmail]]></category>
		<category><![CDATA[邮件转发]]></category>

		<guid isPermaLink="false">http://blog.wdicc.com/wordpress/howto-cc-an-email-to-others-in-sendmail/</guid>
		<description><![CDATA[sendmail有个 /etc/aliases 配置文件，在里面可以给某个帐号设置alias，这样给这个alias发的邮件，都会给设置好的用户转发过去。要知道sendmail的帐号是和系统帐号联系在一起的，添加mail帐号得给系... ]]></description>
			<content:encoded><![CDATA[<p>sendmail有个 /etc/aliases 配置文件，在里面可以给某个帐号设置alias，这样给这个alias发的邮件，都会给设置好的用户转发过去。要知道sendmail的帐号是和系统帐号联系在一起的，添加mail帐号得给系统添加帐号（qmail可以实现虚拟用户，或许sendmail也可以，而我不知道罢了）。而这个alias帐号却不是必须有得有系统帐号的，只要设置了alias，就可以给alias用户发邮件，就好像系统真有这么一个帐号一样。</p>
<p>关于 /etc/aliases 文件，<a href="http://www.feep.net/sendmail/tutorial/intro/aliases.html">这里</a>有个文章有说明。下面复制几个例子。</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;"># RFC 822 规定每个域名都需要有一个 &quot;postmaster&quot; 
postmaster      : root
&nbsp;
# 将 postmaster 的邮件都转发给 root 帐号，当然你下面还可以将root帐号的邮件在转发给别人。
&nbsp;
# 转发也可以转发到文件
# 比如这个，都说了nobody了还给发邮件，邮件都丢掉
nobody          : /dev/null
&nbsp;
# 也可以通过管道作为另一个程序的输入
# 比如给procmail，它能实现的功能可就多了，比如可以根据邮件大小转发到不同的用户，或者调用spamassian、clamav来查垃圾邮件和病毒等
# 一个自动的bug跟踪程序
program-bugs: |/usr/local/bin/program-bug-tracker
&nbsp;
# 也可以转发到多个帐号，用逗号分隔就可以
project-list: johndoe@host1.uiuc.edu,jsmith@host2.uiuc.edu,someone@host.purdue.edu</pre></div></div>

<p>可以看到功能还是很强悍的，尤其是可以 pipe 到程序，procmail、maildrop都是很不错的过滤程序，能实现很多其他的功能。</p>
<p>标题的要求是“抄送”某个帐号的邮件给别的用户，有点类似监控的意思。怎么实现呢？可能第一个想到的就是类似下面这种方法：</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">somebody:other1,other2,somebody</pre></div></div>

<p>这样是不是就能实现抄送呢？这样会造成死循环，呵呵。</p>
<p>看样子似乎只能通过pipe到程序实现了，看procmail、maildrop的文档还不够头疼的。其实还有个简单的方法，就是 <a href="http://www.feep.net/sendmail/tutorial/intro/forward.html">.forward</a> 文件。</p>
<p>.forward 文件位于用户的 home 下面，权限是 600 。他的功能和 /etc/aliases 文件类似，不过是 aliases 文件只能由root用户来修改，而 .forward 文件用户自己就可以修改。除了上面aliases能做到的事情外，他还多了一个功能，就是标题要求的功能。</p>
<p>按照标题的要求，只需要在 somebody 用户的 .forward 文件中放入下面的内容就可以了。</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">\\somebody
other1
other2</pre></div></div>

<p>要注意 somebody 前面的那个\，就是用来防止转发死循环的。加了\之后，给somebody转发的时候会忽略该用户的 .forward 文件。</p>
]]></content:encoded>
			<wfw:commentRss>http://wdicc.com/howto-cc-an-email-to-others-in-sendmail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
