Code Comments
Programming Forum and web based access to our favorite programming groups.How can i create a message with mime::lite but send it with net::smpt_auth?
My attempt below...
use strict;
use warnings;
use MIME::Lite;
use Net::SMTP_auth;
my $msg =3D MIME::Lite -> new ( From =3D> 'me@server.com',
=09=09=09 TO =3D> 'me@server.com',=09=09=09 Subject =3D> '=
Testing
Text Message',
=09=09=09 Data =3D> 'How\'s it going.' );
my $msgbody =3D $msg -> as_string();
print "$msgbody\n";
my $smtp =3D Net::SMTP_auth -> new( 'server.domain.com' );
$smtp -> auth( 'CRAM-MD5', 'me', 'mepassword' );
$smtp -> data();
$smtp -> datasend($msgbody);
$smtp -> dataend();
$smtp -> quit;
This does not work. It fails silently.
If i use the canned example for Net::SMTP_auth i do get the message...
use Net::SMTP_auth;
$smtp =3D Net::SMTP_auth->new('mailhost');
$smtp->auth('CRAM-MD5', 'user', 'password');
$smtp->mail($ENV{USER});
$smtp->to('postmaster');
$smtp->data();
$smtp->datasend("To: postmaster\n");
$smtp->datasend("\n");
$smtp->datasend("A simple test message\n");
$smtp->dataend();
$smtp->quit;
Post Follow-up to this messageOn Tue, 19 Apr 2005 14:52:34 -0400, paul.kraus@gmail.com (Paul Kraus)
wrote:
>How can i create a message with mime::lite but send it with net::smpt_auth?
>
>My attempt below...
>use strict;
>use warnings;
>use MIME::Lite;
>use Net::SMTP_auth;
>my $msg = MIME::Lite -> new ( From => 'me@server.com',
> TO => 'me@server.com', Subject => 'Testing
>Text Message',
> Data => 'How's it going.' );
>my $msgbody = $msg -> as_string();
>print "$msgbody\n";
>my $smtp = Net::SMTP_auth -> new( 'server.domain.com' );
>$smtp -> auth( 'CRAM-MD5', 'me', 'mepassword' );
#You forgot to give it some MAIL command
$smtp->mail('z@zentara.zentara.net');
$smtp->to('zentara@zentara.zentara.net');
>$smtp -> data();
>$smtp -> datasend($msgbody);
>$smtp -> dataend();
>$smtp -> quit;
>
>This does not work. It fails silently.
I ran your script as you posted, and the error was
500 No MAIL Command, so I figured you need the
"from" and "to" methods defined.
Below is a full working script. I've noticed with Net::SMTP,
that it does alot of error checking (for servers and email
address format) so you have to give "good" values.
I noticed when Net::SMTP is installed, it asks if you
want it to "check for valid servers", so if you answered "yes",
make sure you have a local server, or you are online.
#!/usr/bin/perl
use warnings;
use strict;
use MIME::Lite;
use Net::SMTP_auth;
my $msg = MIME::Lite -> new (
From => 'z@zentara.zentara.net',
TO => 'zentara@zentara.zentara.net',
Subject => 'Testing Text Message',
Data => 'How's it going.' );
#my $msgbody = $msg->as_string();
my $smtp = Net::SMTP_auth -> new( 'zentara.zentara.net' );
$smtp -> auth( 'CRAM-MD5', 'z', 'ztest' );
$smtp->mail('z@zentara.zentara.net');
$smtp->to('zentara@zentara.zentara.net');
$smtp -> data();
$smtp -> datasend( $msg->as_string() );
$smtp -> dataend();
$smtp -> quit;
__END__
You may also find this interesting, if you want SSL too.
http://perlmonks.org?node_id=448372
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.