CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Emailing with Mail::Send

 



frist44
User

Jan 9, 2009, 7:51 AM

Post #1 of 8 (667 views)
Emailing with Mail::Send Can't Post

We're using Ldirectord to load balance some websites. Ldirectord has the ability to send email alerts. The Ldirectord program is one big perl script. So i'm going through to the source to understand why email alerts aren't being sent and nothing is being printed to the log. Our system is Debian with Exim4 configured to direct to a smart host and it's been tested to work.

Based on the manual, Ldirectord uses Mail::Send to send the mails. Here is the sub in Ldirectord:


Code
# ld_emailalert 
# Send email alerts per virtual server
# pre: message: Message to email
# post: message is emailed if emailalert defined for virtualserver
# return: 0 on success
# 1 on error
sub ld_emailalert
{
my ($emailsubject, $emailto, $currentserver, $currenttime) = (@_);
my $emailmsg;
my $emailfh;
my $status = 0;

if (not defined $emailto) {
$emailto = $EMAILALERT;
}
if ($emailto eq "") {
return 0;
}

use Mail::Send;

unless ($emailmsg = new Mail::Send Subject=>$emailsubject, To=>$emailto
and $emailfh = $emailmsg->open
and print $emailfh ""
and $emailfh->close) {
&ld_log("failed to send email message\n");
$status = 1;
}

&ld_set_email_status($currentserver, $currenttime);

return($status);
}


Based on this page (http://search.cpan.org/~markov/MailTools-1.77/Mail/Mailer.pm) there is no specific method specific (there is no reference to the Mail::Mailer module), so it uses the "default" which I have no idea what it is.

any ideas? or where to look?


FishMonger
Veteran / Moderator

Jan 9, 2009, 8:13 AM

Post #2 of 8 (666 views)
Re: [frist44] Emailing with Mail::Send [In reply to] Can't Post

Quoted from the Mail::Send doc:

Quote
Sending

$obj->open(OPTIONS)

The OPTIONS are used to initiate a mailer object via Mail::Mailer::new(). Then Mail::Mailer::open() is called with the knowledge collected in this Mail::Send object.


Quoted from the Mail::Mailer doc:

Quote
Sends mail using any of the built-in methods. As TYPE argument to new(), you can specify any of

sendmail

Use the sendmail program to deliver the mail.
smtp

Use the smtp protocol via Net::SMTP to deliver the mail. The server to use can be specified in @args with

$mailer = Mail::Mailer->new('smtp', Server => $server);

The smtp mailer does not handle Cc and Bcc lines, neither their Resent-* fellows. The Debug options enables debugging output from Net::SMTP.

You may also use the Auth => [ $user, $password ] option for SASL authentication (requires Authen::SASL and MIME::Base64).
qmail

Use qmail's qmail-inject program to deliver the mail.
testfile

Used for debugging, this displays the data to the file named in $Mail::Mailer::testfile::config{outfile} which defaults to a file named mailer.testfile. No mail is ever sent.

Mail::Mailer will search for executables in the above order. The default mailer will be the first one found.



frist44
User

Jan 9, 2009, 8:26 AM

Post #3 of 8 (664 views)
Re: [FishMonger] Emailing with Mail::Send [In reply to] Can't Post

yes, i've referenced all this. In the script, there is no reference to the Mail::Mailer module, only the Mail::Send as seen in the code snippet.

Even if it was using the default order of methods, there is a slink on the machine for Sendmail pointing to Exim4, which is configured and tested. So i don't know where else it would try to go. And on top of that, the code clearly shows that it will log the behavior, but nothing has been printed in the logs about the ability/inability to send emails.


FishMonger
Veteran / Moderator

Jan 9, 2009, 8:57 AM

Post #4 of 8 (661 views)
Re: [frist44] Emailing with Mail::Send [In reply to] Can't Post


In Reply To
yes, i've referenced all this. In the script, there is no reference to the Mail::Mailer module, only the Mail::Send as seen in the code snippet.

Mail::Mailer is a dependence of Mail::Send and is loaded via a require statement in Mail::Send and that is how it's being referenced. There is no real need to explicitly reference (use or require) it within your script.
http://search.cpan.org/src/MARKOV/MailTools-2.04/lib/Mail/Send.pm


In Reply To
Even if it was using the default order of methods, there is a slink on the machine for Sendmail pointing to Exim4, which is configured and tested. So i don't know where else it would try to go.

I'm not sure what you mean. Are you saying the slink is pointing to the sendmail executable on a different box?



In Reply To
And on top of that, the code clearly shows that it will log the behavior, but nothing has been printed in the logs about the ability/inability to send emails.

If neither the the success or failure log entries are being made, then it's very likely that the sub is not being executed.


FishMonger
Veteran / Moderator

Jan 9, 2009, 9:03 AM

Post #5 of 8 (660 views)
Re: [frist44] Emailing with Mail::Send [In reply to] Can't Post

One possible issue I see is the loading of the Mail::Send module in the sub. I would need to run a test to be sure, but I think that since the use statement is inside the sub, it may be loaded at run time instead of compile time. If that's the case, it could be failing to load and the script instead of trapping that, it exits with a fatal error.


frist44
User

Jan 9, 2009, 9:22 AM

Post #6 of 8 (658 views)
Re: [FishMonger] Emailing with Mail::Send [In reply to] Can't Post

OK, I understand what you're saying, so I won't see any reference for Mail::Mailer.

On our Debian system. When Exim4 is installed, it creates an slink for sendmail that points to Exim4. So if I type # sendmail in the console, the info for Exim comes up, so it seems like if it were trying to use Sendmail, it should work ok.

I'm guessing you're right in saying that it's not even getting to the sub in the first place, otherwise, I would see some reference to its execution in the logs.

This is a package that a lot of people are using and I would doubt that the reference to Mail::Send in the sub is causing the problem, as it's in the Debian stable repositories.

hmm....


frist44
User

Jan 9, 2009, 9:33 AM

Post #7 of 8 (657 views)
Re: [frist44] Emailing with Mail::Send [In reply to] Can't Post

I figured it out.

This is stupid. The manual says to put quotes around your email in the config file. I removed the quotes and it worked...

ugh.....


KevinR
Veteran


Jan 9, 2009, 9:55 AM

Post #8 of 8 (654 views)
Re: [FishMonger] Emailing with Mail::Send [In reply to] Can't Post


In Reply To
One possible issue I see is the loading of the Mail::Send module in the sub. I would need to run a test to be sure, but I think that since the use statement is inside the sub, it may be loaded at run time instead of compile time. If that's the case, it could be failing to load and the script instead of trapping that, it exits with a fatal error.


it does not matter where a "use" statment is, they all load at compile time, even inside a block of code.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives