Getting MIME::Lite working on Windows

Getting MIME::Lite working on Windows

am 23.04.2008 18:28:11 von Curtis Leach

Hi All,

I need some help with MIME::Lite on Windows.

I'm running ActivePerl 5.8.8 Build 817 on all my Windows boxes & I just
finished installing the MIME-Lite-3.01 from the Active State PPM
repository, along with all the pre-requisite modules.

I'm attempting to port a perl program from AIX Unix where this program
works down to Windows where it breaks.

I only have a requirement to send out emails, not to receive any emails.

The program uses "use strict;" & "use warnings" so I'm assuming I didn't
get something configured correctly on Windows.

Can someone give me a hint or two to check out?

Here's the relevant code from my program:

eval
{
my %mail_args = ( From => $from,
To => $mail_list,
Subject => $subject,
Type => 'TEXT',
Data => $mail_body ) ;
my $msg = MIME::Lite->new( %mail_args );
$msg->send ('smtp');
};
if ($@)
{
print STDERR "Failure sending email: $@\n";
}

The call to $msg->send ('smtp') is throwing the following exception:
Failure sending email: Failed to connect to mail server: Bad file
descriptor at notify.pl line 478.

If I used the call I use for AIX unix, $msg->send ('smtp', 'localhost',
Dbug=>0);
I get the following message:
Failure sending email: Failed to connect to mail server: Unknown error
at notify.pl line 478.

If I try just $msg->send (), I just get a message that it can't find the
sendmail program and no exception is thrown. And no email is sent out.

So I'm assuming that it's because it can't locate the mail server to use
on the Windows platform.

Is there any way to ask Windows what mail servers are available? I'd
hate to have to hard code one that isn't available at all the locations
this program would be installed on. I'd rather add code to ask for it.

Curtis



_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Getting MIME::Lite working on Windows

am 23.04.2008 19:15:24 von Octavian Rasnita

Instead of the line:

$msg->send ('smtp');

try:

$msg->send ('smtp', '127.0.0.1');

and replace 127.0.0.1 with the host or IP of the SMTP server you want to
use.

Octavian

----- Original Message -----
From: "Curtis Leach"
To:
Sent: Wednesday, April 23, 2008 7:28 PM
Subject: Getting MIME::Lite working on Windows


> Hi All,
>
> I need some help with MIME::Lite on Windows.
>
> I'm running ActivePerl 5.8.8 Build 817 on all my Windows boxes & I just
> finished installing the MIME-Lite-3.01 from the Active State PPM
> repository, along with all the pre-requisite modules.
>
> I'm attempting to port a perl program from AIX Unix where this program
> works down to Windows where it breaks.
>
> I only have a requirement to send out emails, not to receive any emails.
>
> The program uses "use strict;" & "use warnings" so I'm assuming I didn't
> get something configured correctly on Windows.
>
> Can someone give me a hint or two to check out?
>
> Here's the relevant code from my program:
>
> eval
> {
> my %mail_args = ( From => $from,
> To => $mail_list,
> Subject => $subject,
> Type => 'TEXT',
> Data => $mail_body ) ;
> my $msg = MIME::Lite->new( %mail_args );
> $msg->send ('smtp');
> };
> if ($@)
> {
> print STDERR "Failure sending email: $@\n";
> }
>
> The call to $msg->send ('smtp') is throwing the following exception:
> Failure sending email: Failed to connect to mail server: Bad file
> descriptor at notify.pl line 478.
>
> If I used the call I use for AIX unix, $msg->send ('smtp', 'localhost',
> Dbug=>0);
> I get the following message:
> Failure sending email: Failed to connect to mail server: Unknown error
> at notify.pl line 478.
>
> If I try just $msg->send (), I just get a message that it can't find the
> sendmail program and no exception is thrown. And no email is sent out.
>
> So I'm assuming that it's because it can't locate the mail server to use
> on the Windows platform.
>
> Is there any way to ask Windows what mail servers are available? I'd
> hate to have to hard code one that isn't available at all the locations
> this program would be installed on. I'd rather add code to ask for it.
>
> Curtis
>
>
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Getting Mime::Lite working on Windows

am 23.04.2008 22:20:08 von pcapacio

> On April 23, 2008, "Curtis Leach" said:
Subject: Getting MIME::Lite working on Windows
> I need some help with MIME::Lite on Windows.
> [snip]
> If I used the call I use for AIX unix,
>$msg->send ('smtp', 'localhost', Dbug=>0);
> I get the following message:
> Failure sending email: Failed to connect to mail server: Unknown
error
> at notify.pl line 478.
>
> So I'm assuming that it's because it can't locate the mail server to
use
> on the Windows platform.
>
> Is there any way to ask Windows what mail servers are available? I'd
> hate to have to hard code one that isn't available at all the
locations
> this program would be installed on. I'd rather add code to ask for
it.
>
I *think* 'localhost' is causing it to look for a mail server on your
local machine. Try setting 'localhost' to 'mailhost'. I'm using
MIME::Lite on windows and I don't hard code specific locations; I
use 'mailhost'.

I can't claim to know exactly why this works, but by specifying 'smtp',
you are indicating you want MIME::Lite to use the Net::SMTP module to
actually send the message. The help for that module indicates you can
find the actual mail server using the following code:
#(ie: asking what mail server is available)
use Net::SMTP;
$smtp = Net::SMTP->new('mailhost');
print $smtp->domain,"\n";
$smtp->quit;
HTH, Paula


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

RE: Getting MIME::Lite working on Windows

am 25.04.2008 16:06:42 von Curtis Leach

Thanks to everyone who responded.

I ended up having to put the SMTP server name to use into a config file.
Since I couldn't figure out a way to ask Windows/Outlook in Perl what it
was configured to use.

Curtis


-----Original Message-----
From: Octavian Rasnita [mailto:orasnita@gmail.com]
Sent: Wednesday, April 23, 2008 12:15 PM
To: Curtis Leach; activeperl@listserv.ActiveState.com
Subject: Re: Getting MIME::Lite working on Windows

Instead of the line:

$msg->send ('smtp');

try:

$msg->send ('smtp', '127.0.0.1');

and replace 127.0.0.1 with the host or IP of the SMTP server you want to
use.

Octavian

----- Original Message -----
From: "Curtis Leach"
To:
Sent: Wednesday, April 23, 2008 7:28 PM
Subject: Getting MIME::Lite working on Windows


> Hi All,
>
> I need some help with MIME::Lite on Windows.
>
> I'm running ActivePerl 5.8.8 Build 817 on all my Windows boxes & I
just
> finished installing the MIME-Lite-3.01 from the Active State PPM
> repository, along with all the pre-requisite modules.
>
> I'm attempting to port a perl program from AIX Unix where this program
> works down to Windows where it breaks.
>
> I only have a requirement to send out emails, not to receive any
emails.
>
> The program uses "use strict;" & "use warnings" so I'm assuming I
didn't
> get something configured correctly on Windows.
>
> Can someone give me a hint or two to check out?
>
> Here's the relevant code from my program:
>
> eval
> {
> my %mail_args = ( From => $from,
> To => $mail_list,
> Subject => $subject,
> Type => 'TEXT',
> Data => $mail_body ) ;
> my $msg = MIME::Lite->new( %mail_args );
> $msg->send ('smtp');
> };
> if ($@)
> {
> print STDERR "Failure sending email: $@\n";
> }
>
> The call to $msg->send ('smtp') is throwing the following exception:
> Failure sending email: Failed to connect to mail server: Bad file
> descriptor at notify.pl line 478.
>
> If I used the call I use for AIX unix, $msg->send ('smtp',
'localhost',
> Dbug=>0);
> I get the following message:
> Failure sending email: Failed to connect to mail server: Unknown
error
> at notify.pl line 478.
>
> If I try just $msg->send (), I just get a message that it can't find
the
> sendmail program and no exception is thrown. And no email is sent
out.
>
> So I'm assuming that it's because it can't locate the mail server to
use
> on the Windows platform.
>
> Is there any way to ask Windows what mail servers are available? I'd
> hate to have to hard code one that isn't available at all the
locations
> this program would be installed on. I'd rather add code to ask for
it.
>
> Curtis
>
>
>
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Re: Getting MIME::Lite working on Windows

am 28.04.2008 14:21:36 von Bill Luebkert

Curtis Leach wrote:
> Thanks to everyone who responded.
>
> I ended up having to put the SMTP server name to use into a config file.
> Since I couldn't figure out a way to ask Windows/Outlook in Perl what it
> was configured to use.

Try something like:

use strict;
use warnings;
use Win32::OLE::Const 'Microsoft Outlook';

my $OL = Win32::OLE->GetActiveObject('Outlook.Application') or
Win32::OLE->new('Outlook.Application', 'Quit');
die 'GetActiveObject -> new failed' if not $OL; # try opening OE if you err here

my $NameSpace = $OL->GetNameSpace("MAPI");
my $EmailAddr = $NameSpace->{CurrentUser}{Address};
print "Email=$EmailAddr\n";

__END__
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs