开发者

SMTP Authentication problem

I'm writing a simple mail client in Perl, that uses SMTP to log in a Mail server, and from there sends a mail to another E-mail address (on different host). I use raw SMTP command开发者_高级运维s, because strawberry perl doesn't come with SASL.pm which is needed in order to authenticate. However, when the script tries to authenticate itself, it fails. I tried 'AUTH LOGIN' and 'AUTH PLAIN' mechanism but no luck. Here is an example:

EHLO example.com
AUTH LOGIN
YWxwaGE=
cGFzc3dvcmQ=
MAIL FROM:<alpha@example.com>
RCPT TO:<beta@betadomain.com>
DATA
Subject: sample message
From: alpha@example.com
To: beta@betadomain.com

Greetings,
Typed message (content)
Goodbye.
. 
QUIT
EOT

"YWxwaGE=", "cGFzc3dvcmQ=" are the user and password encoded in Base64. Whatever I submit the server always complains that either the username or the password is wrong. What do I do wrong?


Why not just install a module that supports SMTP with SASL? One of the advantages of Strawberry Perl is that you can easily install modules from CPAN.

For example, Email::Simple and Email::Sender:

use strict;
use warnings;
use Email::Sender::Simple qw(sendmail);
use Email::Simple;
use Email::Simple::Creator;
use Email::Sender::Transport::SMTP;

my $email = Email::Simple->create(
  header => [
    To      => 'beta@betadomain.com',
    From    => 'alpha@example.com',
    Subject => "sample message",
  ],
  body => "Greetings,\nTyped message (content)\nGoodbye.\n",
);

my $transport = Email::Sender::Transport::SMTP->new({
  host => 'smtp.example.com',
  sasl_username => 'foo',
  sasl_password => 'bar',
});

sendmail($email, { transport => $transport });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜