Set up MIME::Lite on Windows 7 without Outlook
I run ActiveState's ActivePerl on my Windows 7 box. I just installed the MIME::Lite module using the PPM (Perl Package Manager). The installation went fine.
However, as I try to run a very simple script
use strict;
use MIME::Lite;
my $msg = MIME::Lite->new(
From => 'myname@host.com',
To => 'myname@host.com',
Subject => "Mail Test",
Data => "Test Test!!",
);
$msg->send;
I got this error:
SMTP Failed to connect to mail server: at C:\...\开发者_如何学编程mail_test.pl line 10
Does that mean I need to install a 3rd party mail server on my windows? Or can I configure the script and/or windows to make it work without new installation? In particular, I do not run outlook on that machine. Thx!
You need to give it a host to send the mail through, otherwise its going to try and use the SMTP server on your computer which A) you don't have and B) if its a home computer many would reject it as spam anyway.
The MIME::Lite documentation shows how to tell it what SMTP host to use. Set it up with the same host, username and password as you would your normal mail client.
Unfortunately, MIME::Lite doesn't support encryption so your mail will be going out insecure and in the clear. Some mail servers won't even talk unencrypted any more. Email::Sender I believe is what the email folks recommend you use these days.
精彩评论