SyntaxHighlighter

2011年9月12日月曜日

IO::Socket::INET でメール送信(smtp-auth対応)

#!/usr/bin/perl

use strict;
use IO::Socket::INET;
use MIME::Base64;

my $server = 'mail.hoge.com';
my $port = 587;
my $fqdn = 'my.fqdn';
my $user = 'username';
my $passwd = 'password';
my $from = 'hoge@hoge.com';
my $to = 'foo@bar.com';

$user = encode_base64($user,'');
$passwd = encode_base64($passwd,'');

my $sock = IO::Socket::INET->new(PeerAddr => "$server:$port", Proto => 'tcp') or die;
print $sock <<"END_OF_DATA";
EHLO $fqdn
AUTH LOGIN
$user
$passwd
MAIL FROM: $from
RCPT TO: $to
DATA
From: $from
To: $to
Subject: sock test

test mail with sock
.
QUIT
END_OF_DATA
$sock->close();

exit;

0 件のコメント:

コメントを投稿