views:

46

answers:

1

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 commands, 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:<[email protected]>
RCPT TO:<[email protected]>
DATA
Subject: sample message
From: [email protected]
To: [email protected]

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?

+1  A: 

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      => '[email protected]',
    From    => '[email protected]',
    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 });
cjm
I tried your code - still no luck.
Tichomir Mitkov
Never mind, I solved the problem :)
Tichomir Mitkov