2

Perl を使用して電子メール メッセージを送信しようとしています。基本的に、レポートを適切な形式で出力する Perl スクリプトがあります。そのレポートをメールで送ってほしい。これどうやってするの?

4

4 に答える 4

4

マシンに sendmail が構成されていない場合、通常はMail::Sendmailを使用します。

use Mail::Sendmail;

%mail = (smtp    => 'my.isp.com:25',
         to      => 'foo@example.com',
         from    => 'bar@example.com',
         subject => 'Automatic greetings',
         message => 'Hello there');

sendmail(%mail) or die;
于 2012-06-07T21:33:11.920 に答える
3

マシンにOutlookがインストールされていて、Outlookモジュールをcpanしている場合は、次の点に注意してください。

 # create the object
 use Mail::Outlook;
 my $outlook = new Mail::Outlook();

  # start with a folder
  my $outlook = new Mail::Outlook('Inbox');

  # use the Win32::OLE::Const definitions
  use Mail::Outlook;
  use Win32::OLE::Const 'Microsoft Outlook';
  my $outlook = new Mail::Outlook(olInbox);

  # get/set the current folder
  my $folder = $outlook->folder();
  my $folder = $outlook->folder('Inbox');

  # get the first/last/next/previous message
  my $message = $folder->first();
  $message = $folder->next();
  $message = $folder->last();
  $message = $folder->previous();

 # read the attributes of the current message
 my $text = $message->From();
 $text = $message->To();
 $text = $message->Cc();
 $text = $message->Bcc();
 $text = $message->Subject();
 $text = $message->Body();
  my @list = $message->Attach();

  # use Outlook to display the current message
  $message->display;


  # Or use a hash
  my %hash = (
    To      => 'suanna@live.com.invalid',
    Subject => 'Blah Blah Blah',
     Body    => 'Yadda Yadda Yadda',
  );

  my $message = $outlook->create(%hash);
  $message->display(%hash);
  $message->send(%hash);

.invalid TLDは実際のものではないため、上記のアドレスは配信されないことに注意してください。いずれにせよ、私はここにモジュール内の物事のまともな説明を入れました-これはメッセージを送信します!

于 2012-06-07T20:50:55.997 に答える
3

MIME::Liteは多くの人が使用する強力なモジュールです。書類を添付する場合も含め、使いやすいです。

use MIME::Lite;
my $msg = MIME::Lite->new(
    From    => $from,
    To      => $to,
    Subject => $subject,
    Type    => 'text/plain',
    Data    => $message,
);
$msg->send;

(SMTP ではなく) デフォルトで使用sendmailされるため、構成する必要さえありません。

于 2012-06-07T20:30:10.173 に答える