2012-02-13 11 views
1

自分のサイトでいくつかのスタータースクリプトを使ってperlに飛び込むことにしました。私はhttp://learn.perl.org/examples/email.htmlで始まり、基本的な電子メール送信スクリプトを試してみました。Perl電子メールスクリプト - コンテンツエンコーディングの問題

はここで実際のコードです:

#!/usr/bin/perl 
use strict; 
use warnings; 

#Character encoding var 
my $encoding='text/plain; charset="iso-8859-5"'; 

#Create the message 
use Email::MIME; 
my $message = Email::MIME->create(
     header_str => [ 
       From => '[email protected]', 
       To => '[email protected]', 
       Subject => 'I sent you this message using Perl.', 
     ], 
     body_str => 'I sent you this message using Perl. One of those languages that would\' would\'ve been helpful much sooner in my life...', 
     ); 
use Email::Sender::Simple qw(sendmail); 
sendmail($message); 

私はperl script.plを行うときに、私は何を得るの

body_str was given, but no charset is defined at /usr/local/share/perl/5.10.1/Email/MIME.pm line 243 
    Email::MIME::create('Email::MIME', 'header_str', 'ARRAY(0x9a04818)', 'body_str', 'I sent you this message using Perl. One ...') called at script.pl line 10 

のエラーメッセージである私は、電子メール:: MIMEモジュールの周りにいくつかの検索を行なったし、body_strを見つけましたエラーメッセージに何も表示されませんでした。私はエンコーディングを設定する必要があると思っていますが、それをやり遂げる方法はわかりません。

+0

@cjmのおかげで、この例は修正されました。ありがとうございました! –

答えて

5

SYNOPSIS section of the docsを見ると、create()に「属性」ハッシュリファレンスを渡すこともできます。ここで文字セットを定義できます。ここでもエンコーディングを定義する必要があるかもしれません。たとえば、次のようにすることができます。

my $message = Email::MIME->create(
    header_str => [ 
      From => '[email protected]', 
      To  => '[email protected]', 
      Subject => 'I sent you this message using Perl.', 
    ], 
    attributes => { 
     encoding => 'quoted-printable', 
     charset => "US-ASCII", 
    }, 
    body_str => 'I sent you this message using Perl. One of those languages that would\' would\'ve been helpful much sooner in my life...', 
); 
+0

ところで、learn.perl.orgのソースは[GitHubで利用できます](https://github.com/perlorg/perlweb)です。私は[これを修正するためのプルリクエスト](https://github.com/perlorg/perlweb/pull/35)を送ってきました。 – cjm

+0

それはトリックでした!属性を追加していくつかの追加エラーが発生しましたが、sendmailとpostfixをインストールすることで修正されました。 – Chad

+0

@cwscribner素晴らしい!それが処理したら、これを受け入れられた答えとしてマークすることができます。 :) – oalders