DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Perl Mail Sample

02.05.2006
| 1437 views |
  • submit to reddit
        // description of your code here

<a href="http://www.dive-in.to/~tom/webpage/cgi/cgi-faq.html">
http://www.dive-in.to/~tom/webpage/cgi/cgi-faq.html
</a>
use MIME::Lite;

# $msg ���オブジェクトを生��る
my $msg = new MIME::Lite(From=>'sender@bar.com',
                         To=>'receiver@foo.com',
                         Subject=>'test : attached file',
                         Type=>'multipart/mixed');

# 説明文
$msg->attach(Type=>'TEXT',
                Data=>"jpeg file following:");
# 添付ファイルを加�る(アタッ�)
$msg->attach(Type=>'image/jpeg',	# ファイルタイプ
             Path=>'labo.jpg',	# ファイル�パス
             Encoding=>'base64',	# エンコード(��ーbase64)
             Filename=>'labo.jpg');	# 復元ã?™ã‚‹éš›ã?®ãƒ•ã‚¡ã‚¤ãƒ«å??

# sendmail ã?¸ã?®ãƒ‘イプを開ã??
open(M, "|/usr/lib/sendmail -t") || die;
# ã??ã?®ãƒ•ã‚¡ã‚¤ãƒ«ãƒ?ンドルã?¸å‡ºåŠ›
$msg->print(\*M);
# 閉�る
close M;

send mail by perl
use Mail::Sendmail;
%mail = ( smtp    => 'your.smtp.server',
          To      => 'yourfriend@mail.address',
          From    => 'your@mail.address',
          Subject => 'ipconfig ouput',
          Message => ($ipconfig = `ipconfig`)
        );
sendmail(%mail) or die $Mail::Sendmail::error;
print "OK. Log says:\n", $Mail::Sendmail::log;

pop3
use Net::POP3;
$pop = Net::POP3->new('yourserver');

# POPサーãƒ?ã?«ãƒ¦ãƒ¼ã‚¶å??ã?¨ãƒ‘スワードã?§æŽ¥ç¶š
if($pop->login('username', 'password') >= 0) {
$pop->quit; # 接続ã?§ã??ã?Ÿã‚‰Net::POP3終了
}else{
die "can not login.\n"; # 接続ã?§ã??ã?ªã?‘ã‚Œã?°ã‚¨ãƒ©ãƒ¼
}