sylph001 has asked for the wisdom of the Perl Monks concerning the following question:

I'm installing my perl script on one server and expecting the script to send out an email to a group email address so everybody in the group can receive this email.
However after install, I noticed the emails sent to the group was not received at all.

In order to find out the reason, I wrote test scripts to test sending emails from three different servers. These three serves reside in the same network.

On each server, I tried two different methods to send email that I know so far, hoping to give better coverage for the test.
Method 1:  MIME::Lite   (which is also used in my script installed at the beginning)

my $msg = MIME::Lite->new( To => 'Alias@xxxx.com', Subject = $subject, Type => 'text/plain, Data => $message );

Method 2: system function call

open $CMD, "|/usr/bin/mailx -s \'$subject\' Alias\@xxxx.com" or die("C +annot open CMD"); print $CMD $message; close $CMD;

I tested to send the email to both the group email address and my individual email address respectively, for comparison.
The result looks interesting and I hadn't expected our servers to vary so much on this issue:

Server A: Send to group address fails    Send to individual address OK
Server B: Send to group address fails    Send to individual address fails
Server C: Send to group address fails    Send to individual address OK

My Monks, based on my tests, do you think we can locate the email problem, or does it look like it's caused by some other configurations from each of the servers?

My second question is, could you let me know if there is any better way of sending emails by perl, that's possibly safer?


Many thanks

Replies are listed 'Best First'.
Re: Send email and attachement without MIME?
by tangent (Parson) on Jul 23, 2015 at 03:59 UTC
    I think MIME::Lite will use the default mailer (e.g. sendmail) unless you tell it otherwise. You may have more luck using SMTP as mail servers tend to treat authenticated emails with more respect. I have just asked my own question about Net::SMTP so have this snippet at hand, using Email::Stuffer. I haven't had any problems with failed deliveries.
    sub send_email { my $msg = shift; my $sender = Email::Stuffer->new; $sender->transport('SMTP', host => 'mail.example.com', sasl_username => 'username', sasl_password => 'password', helo => 'example.com', ssl => 1, debug => 1, ); $sender->to( $msg->{'to'} ); $sender->from( $msg->{'from'} ); $sender->subject( $msg->{'subject'} ); $sender->text_body( $msg->{'body'} ); if ( my $attachments = $msg->{'attachments'} ) { for my $attachment ( @$attachments ) { $sender->attach_file( $attachment ); } } my $sent = $sender->send; return $sent; }
Re: Send email and attachement without MIME?
by 1nickt (Canon) on Jul 23, 2015 at 03:36 UTC

    What do you mean it "fails"? Is there an error message, or do you just mean that the email doesn't arrive? What is the "group address"? Is it an alias or a list of addresses? With what program are you sending the mail under Mime::Lite? Have you tried passing the Debug flag to send() ?

    Sending email is fraught with potential errors: your mailer may fail or reject the message; the recipient's MX may reject the message as spam ... there are a lot of ways the process can fail to succeed, independent of Perl.

    The way forward always starts with a minimal test.
Re: Send email and attachement without MIME?
by Anonymous Monk on Jul 23, 2015 at 04:23 UTC

    Hi,

    From Mime::Lite docs -

    MIME::Lite is not recommended by its current maintainer. There are a number of alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you should probably use instead. MIME::Lite continues to accrue weird bug reports, and it is not receiving a large amount of refactoring due to the availability of better alternatives. Please consider using something else.

    J.C.

      There are indeed many issue reports for MIME::Lite, while there are no (meaningful) test failures according to CPANTS.

      But on the other hand in simple situations it works perfectly. I have a script that runs in a nightly cronjob that sends email to several people daily, using MIME::Lite and MIME::Lite:TT ... never have had a single problem with it. FWIW.

      The way forward always starts with a minimal test.