Scripting Email
Fraser Campbell
fraser-eicrhRFjby5dCsDujFhwbypxlwaOVQ5f at public.gmane.org
Thu Mar 4 16:23:55 UTC 2004
On Thursday 04 March 2004 10:34, William O'Higgins wrote:
> lot of stuff about `mail`. My MTA is just forwarding stuff to a smarthost
> (leave off for the moment that the "smart" host is actually a flaming
> ninnyhammer) and so `mail` doesn't help me.
Is it because of your need for setting custom headers that mail doesn't work?
> I've tried using Perl and Net::SMTP, but it provides insufficient
> control over headers, and gets flagged as spam.
I've never had trouble setting headers using Net::SMTP. Here's how I send
email in one script:
my $smtp = Net::SMTP->new($smtpserver);
$smtp->mail($envelope_from);
$smtp->to($recipient);
if ($smtp->ok()) {
$smtp->data();
$smtp->datasend("Sender: $envelope_from\n");
$smtp->datasend("To: $recipient\n");
$smtp->datasend("From: $sender\n");
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("MIME-Version: 1.0\n");
$smtp->datasend("Content-type: $type; charset=us-ascii\n\n");
$smtp->datasend($message);
$smtp->dataend();
}
IIRC the Sender: header must be sent otherwise the later From header will
overwrite the envelope sender address (which is important in many cases). My
recollection might be wrong, newer versions of Net::SMTP might handle that
better, I might be out to lunch ...
--
Fraser Campbell <fraser-Txk5XLRqZ6CsTnJN9+BGXg at public.gmane.org> http://www.wehave.net/
Georgetown, Ontario, Canada Debian GNU/Linux
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list