Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

MIME::Lite Net::SMTP_auth
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;

Report this thread to moderator Post Follow-up to this message
Old Post
Paul Kraus
04-20-05 01:55 AM


Re: MIME::Lite Net::SMTP_auth
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Zentara
04-22-05 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:21 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.