2005年3月10日 星期四

在Proventia G上送email

因為G上面有Perl 5.8,所以可以直接寫Perl script來做事;不過剛剛發現,Net::SMTP這個module(libnet package)是沒有辦法直接用的,要重新安裝。另外,安裝module時沒有辦法用自動化的方式(Windows下的ppm,Unix的
perl -MCPAN -e shell),所以要用make法。好在雖然G上沒有gcc,但是Perl Module的安裝倒是沒有問題:
下載tar.gz檔,並且上載到G上
tar xvf
cd dir
perl Makefile.PL
make
make test
make install
即可

在Perl Cookbook以及Perl for System Administration兩本書上都有提到Mail::Mailer這個module,但是我試的結果,如果是要利用smtp(也就是自己不架設mail server,用自己有帳號的外部伺服器)來寄的話,它會去叫Net::SMTP來寄…那我為什麼要多費這一道手呢?害我找了半天有關這個module的資料,唉…

其實主要的問題在於,這些書上都未提到認證的問題;而在現在這個spam滿天飛的Internet上,誰不認證簡直就在找死!而我在改用Net::SMTP之後,才發現問題果然出在這裡;在我使用$smtp->auth(user, password)之後,立刻就可以寄了;真是浪費時間。

以下是測試用的script,當然要把一些資料藏起來了:
use Net::SMTP;

$smtp=Net::SMTP->new(
Host => 'mail.hostname.net',
Hello => '10.2.2.23',
Debug => 1,
);

$smtp->auth('user_account','user_password');
$smtp->mail('account@xxx.xxx.xxx');
$smtp->to('account@xxx.xxx.xxx');
$smtp->cc("account\@xxx.xxx.xxx");
$smtp->data();
$smtp->datasend("From: Hahaha\n");
$smtp->datasend("To: sender\n");
$smtp->datasend("Subject: This is an auth mail test\n");
$smtp->datasend("\n");
$smtp->datasend("This is an auth test\n");
$smtp->datasend();

$smtp->quit;

沒有留言: