I'm trying to send emails out using MIME::Lite with authentication.
Here's the code snippet I am trying:
#!/usr/bin/perl
use strict;
use DBI;
use lib '/theannealing.com/perl/';
use MIME::Lite;
use MIME::Base64;
use Authen::SASL;
my $recipient = 'recipient#email.com';
my $mailman = 'sender#email.com';
my $cc_recipient = 'ccrecipient#email.com';
my $subject = 'Subject';
my $email_message = "Message";
my ($user,$pass) = ("username","password");
MIME::Lite->send('smtp','smtp.server:port',AuthUser=>$user, AuthPass=>$pass);
my $email = new MIME::Lite(From => $mailman,To => $recipient,Cc => $cc_recipient,Subject => $subject,Data => "Data",Type => "multipart/mixed");
$email->attach(Type => 'TEXT', Data => "$email_message");
$email->send();
When I execute the script, I get this error message:
Cannot find a SASL Connection library at /usr/lib/perl5/5.8.8/Net/SMTP.pm line 143
I tried searching the error message and couldn't find any worth-while explanations and/or solutions to the problem with relevance to usage with MIME::Lite
Does anyone know what's wrong or what's producing that error message?
UPDATE
Emailing via php using the mail() function works fine from a web browser, but does not work from the command line
You need to reinstall Authen::SASL - it was installed incorrectly. Do this as root from command line:
cpan GBARR/Authen-SASL-2.15.tar.gz
Related
Okay I'm working on finding the latitude and longitude of cities using Perl. I found the Geo::Coder::Google module and have it installed properly, but I'm getting an error when attempting to use it. The first time I got the error I went out and got an API key from Google thinking that was what I was missing, but that didn't solve the error either. Can someone help me figure out what I'm missing?
Here is the error I'm receiving:
Google Maps API returned error: 500 Can't verify SSL peers without knowing which Certificate Authorities to trust at test.pl line 7.
Here is the code I'm using right now:
1:#!/usr/bin/perl
2:use strict;
3:use warnings;
4:
5:use Geo::Coder::Google;
6:my $geocoder = Geo::Coder::Google->new( apiver => 3, gl => 'us', apikey => 'My API Key Here' );
7:my $location = $geocoder->geocode( location => 'Mount Vernon, IN' );
8:
9:print "$location->{'geometry'}->{'location'}->{'lat'}";
10:print "$location->{'geometry'}->{'location'}->{'lng'}";
The code you have written works fine as it stands—you don't need an API key. The problem is that your Secure Socket Layer support for the HTTPS is incomplete
You should start by reinstalling the LWP library to make sure that it is up to date. You should also install Mozilla::CA to make sure that the Certificates of Authority are current. (This is the most likely cause of the problem given the error message that you're getting.)
If it is still not working after that, then the only other culprits I can think of are IO::Socket::SSL and Crypt::SSLeay, but I would be surprised if they are out of date as they should be updated as dependencies of LWP
#!/usr/bin/perl
use strict;
use warnings 'all';
use Geo::Coder::Google;
my $geocoder = Geo::Coder::Google->new( apiver => 3 );
my $info = $geocoder->geocode( location => 'Mount Vernon, IN' );
my $location = $info->{geometry}{location};
printf "%s %s\n", $location->{lat}, $location->{lng};
output
37.9322662 -87.8950267
Try:
sudo cpan
install LMP::UserAgen Mozilla::CA
I am trying to send my first email (from a windows machine) with Perl, but I am getting an error:
SMTP Failed to connect to mail server: at emailer2.pl line 18 (msg->send;)
I am totally new to Perl so any help would be greatly appreciated. Has anyone encountered this problem before? I have searched for the error but I had no luck finding my exact problem.
Thanks so much for your help!
CODE:
#!/usr/bin/perl
use MIME::Lite;
$to = 'myemail#gmail.com';
$cc = 'myemail#gmail.com';
$from = 'myemail#gmail.com';
$subject = 'Test Email';
$message = 'This is test email sent by Perl Script';
$msg = MIME::Lite->new(
From => $from,
To => $to,
Cc => $cc,
Subject => $subject,
Data => $message
);
$msg->send;
print "Email Sent Successfully\n";
It means you don't have a mail server running on your machine. You need to install one and make sure it is running.
You may also use another mail server setting default parameters before sending the message
MIME::Lite->send('smtp', "smpt.example.org", Timeout=>60, SSL=>1,
AuthUser=>"myself", AuthPass=>"mysecret");
Take a look at MIME::Lite sending section.
I am trying to use test perl's email using the example listed from
http://learn.perl.org/examples/email.html. I am running this on Windows 7.
For some reason, Email::Sender::Simple is referencing other modules that are not loaded when Email::Sender is loaded.
How can one load these modules so that all dependencies get loaded without searching in each module for all referenced packages? Currently I am using ActiveState and ppm install.
use 5.14.2;
use strict;
use warnings;
# first, create your message
use Email::MIME;
my $message = Email::MIME->create(
header_str => [
From => 'you#example.com',
To => 'friend#example.com',
Subject => 'Happy birthday!',
],
attributes => {
encoding => 'quoted-printable',
charset => 'ISO-8859-1',
},
body_str => "Happy birthday to you!\n",
);
# send the message
use Email::Sender::Simple qw(sendmail);
sendmail($message);
Of course, I could dump the %INC but the output includes a ton of modules.
Ideally, I would like to load Email::MIME and Email::Sender::Simple and have this work.
I would recommend using Mail::Sender, you can install it in ActivePerl using ppm install Mail::Sender, in Linux install it with
sudo apt-get install libmail-sender-perl
This module is very versatile, supports multiple attachments, inlining, SMTP password authentication (even including NTLM - necessary to talk to Exchange servers).
This is an example to send HTML mail using Mail::Sender:
use Mail::Sender;
my $sender = new Mail::Sender({
# provider may require using port 587:
smtp => "smtp.example.com",
# auth parameters below are optional
# and depend on provider requirements
auth => "LOGIN",
authid => $username,
authpwd => $password,
from => "myself#example.com",
});
$sender->Open({
to => "recipient#example.com",
cc => "anotherguy#example.com",
subject => "Subject line",
ctype => "text/html",
encoding => "7bit",
}) or die ($Mail::Sender::Error, "\n");
my $html = "<html><body>Test HTML content</body></html>";
$sender->SendEx($html)
or die ($Mail::Sender::Error, "\n");
$sender->Close();
print "Test message has been sent\n";
Email::Sender::Simple and just Email::Sender are two different modules, so you have to do this:
From cmd:
C:\>cpan
C:\>install Email::Sender::Simple
That's all.
I am unable to send a mail using MIME::Lite. While sending from my desktop it will through the below errors.
Error: "SMTP Failed to connect to mail server: Bad file descriptor"
I am using the below mentioned code.
use strict;
use MIME::Lite;
use Net::SMTP;
my $from_address = "no-reply#host.com";
my $to_address = "madhan#host.com";
my $cc_address = "madhan#host.com";
my $subject = "Test mail";
my $message_body = "Madhan test mail";
my $namer="madhankumar";
my $regards="Madhan M";
print " Sending mail from $from_address to $to_address \n";
my $person_name=ucfirst($namer).",";
my $mail_host = 'mail1.somehost.com';
my $msg = MIME::Lite->new (
From => $from_address,
To => $to_address,
Cc => $cc_address,
Subject => $subject,
Type =>'multipart/mixed'
) or die "Error creating multipart container: $!\n";
$msg->attach (
Type => 'TEXT',
Data => "Dear $person_name\n\n".$message_body."\n\nRegards,\n$regards"
) or die "Error adding the text message part: $!\n";
MIME::Lite->send('smtp', $mail_host, Timeout=>60);
$msg->send;
The above code is working fine while the mail server is connected with LAN. While using the code in remote system the error has been thrown as mentioned in below
"SMTP Failed to connect to mail server: Bad file descriptor".
May I know the reason.. Is the code run in remote system. If not what are the change I have made the code.. Please share your solutions....
Thanks in advance...
Note: I am developing this in Windows XP
The variables do not contain what you think they contain. If you had switched on warnings, you would have noticed this on your own.
$ perl -e'use warnings; my $from_address = "no-reply#host.com";'
Possible unintended interpolation of #host in string at -e line 1.
Name "main::host" used only once: possible typo at -e line 1.
The remedy is to use single quotes to delimit those strings.
When I try to run my Perl CGI program, the returned web page tells me:
Software error: For help, please send mail to the webmaster (root#localhost), giving this error message and the time and date of the error.
Here is my code in one of the file:
#!/usr/bin/perl
use lib "/home/ecoopr/ecoopr.com/CPAN";
use CGI;
use CGI::FormBuilder;
use CGI::Session;
use CGI::Carp (fatalsToBrowser);
use CGI::Session;
use HTML::Template;
use MIME::Base64 ();
use strict;
require "./db_lib.pl";
require "./config.pl";
my $query = CGI->new;
my $url = $query->url();
my $hostname = $query->url(-base => 1);
my $login_url = $hostname . '/login.pl';
my $redir_url = $login_url . '?d=' . $url;
my $domain_name = get_domain_name();
my $helpful_msg = $query->param('m');
my $new_trusted_user_fname = $query->param('u');
my $action = $query->param('a');
$new_trusted_user_fname = MIME::Base64::decode($new_trusted_user_fname);
####### Colin: Added July 12, 2009 #######
my $view = $query->param('view');
my $offset = $query->param('offset');
####### Colin: Added July , 2009 #######
#print $session->header;
#print $new_trusted_user;
my $helpful_msg_txt = qq[];
my $helpful_msg_div = qq[];
if ($helpful_msg)
The "please send mail to the webmaster" message you see is a generic message that the web server gives you when anything goes wrong and nothing handles it. It's not at all interesting in terms of solving the actual problem. Check the error log to find possible relevant error output from your program.
And, go through my How do I troubleshoot my Perl CGI script? advice on finding the problem.
My guess is that you have a syntax error with that dangling if(). What you have posted isn't a valid Perl program.
Good luck,
is that something related to suexec module
Improper configuration of suExec can cause permission errors
The suEXEC feature provides Apache users the ability to run CGI and SSI programs under user IDs different from the user ID of the calling web server. Normally, when a CGI or SSI program executes, it runs as the same user who is running the web server.
apache recommends that you not consider using suEXEC.
http://httpd.apache.org/docs/2.2/suexec.html
From the StackOverflow page: How to trap program crashes with HTTP error code 500
I see that your include: use CGI::Carp (fatalsToBrowser);
... stifles the HTTP 500 error. Simply removing this will allow the programs to crash "properly".