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

I have a simple Perl script to send email using Sendmail program. When I execute this script from my house (Comcast internet connection) is does not work.

The script does not give any error, and i do not have any mail in the 'mail' of my account. But, I still do not see any email in my inbox. I have checked my 'junk' email folder as well and I do not see email from this script.

The same script works if I am at other location, other than my house.

Do I need to do any additional setup? I am running this on MacBook/OSX 10.9

Thanks.

--Here is my script $to = 'soni.nimesh@gmail.com'; $from = 'soni_nimesh@hotmail.com'; $subject = 'Test Email'; $message = 'This is test email sent by Perl Script'; open(MAIL, "|/usr/sbin/sendmail -t"); # Email Header print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; # Email Body print MAIL $message; close(MAIL); print "Email Sent Successfully\n";

Replies are listed 'Best First'.
Re: Sendmail issue
by neilwatson (Priest) on Aug 08, 2014 at 12:18 UTC

    Isn't this a Sendmail, or email question? The script uses a local Sendmail binary. What do the local Sendmail logs report? Very likely the ISP is blocking the connection.

    Neil Watson
    watson-wilson.ca

Re: Sendmail issue
by hippo (Archbishop) on Aug 08, 2014 at 12:31 UTC
    When I execute this script from my house (Comcast internet connection) is does not work.
    ...
    The same script works if I am at other location, other than my house.

    Natural conclusion: the problem is with your house, or more specifically your "Comcast internet connection". Contact your ISP and ask if they prohibit outbound SMTP traffic other than via their mailservers. I bet you a beer that their answer will be "yes".

Re: Sendmail issue
by Anonymous Monk on Aug 08, 2014 at 12:41 UTC

    Are you carrying your laptop to this other location, or are you executing the script from a different computer? If the former, then the first thing to investigate would be blocked outgoing SMTP, as the other monks have suggested.

    Your open would be better with error handling: open(MAIL, "|/usr/sbin/sendmail -t") or die "Failed to open sendmail: $!"; and the same for your close: close MAIL or die $! ? "Error closing sendmail: $!" : "Exit status $? from sendmail";

      I carry my laptop to other location, and the script works.

      Per your suggestion, I put the error handling and still do not see any error.

      Here is Sendmail log.

      Aug 8 08:59:00 MacBook.local postfix/smtp[15911]: warning: 30A5F1C79A +1F: defer service failure Aug 8 08:59:00 MacBook.local postfix/smtp[15911]: 30A5F1C79A1F: to=<s +oni.nimesh@gmail.com>, relay=none, delay=260447, delays=260356/0.06/9 +0/0, dsn=4.4.1, status=deferred (connect to alt2.gmail-smtp-in.l.goog +le.com[74.125.136.26]:25: Operation timed out)

        This is not a Perl problem. It is a networking problem. SMTP is blocked to keep you or a trojan on your system from spamming from Comcast's IP ranges.

        Check to see if you can instead use the SMTP submission port (587) which is meant for new message submissions. That may be blocked as well.

        If you must use a local MTA (which you shouldn't need to do) then remember that SMTP is not a direct peer-to-peer protocol. It is a store and forward protocol that can use any number of servers along the path. The proper thing to do would be one of two options. You could connect to the proper designated outbound mail server and authenticate (using Net:SMTP, Net::SMTP::TLS, Mail::Sender, ...) to send mail through the ISP's server. You also could set up your mail server to smart forward and send to Comcast's server (agaiun, with authentication if you're sending to other than their recipients).

        I'm not going to give you a lot of free help on configuring your mail server, especially not on Perlmonks. You can totally make your program configurable to send through different servers and accounts as needed, though.

        By the way, if your other connection will allow any client machine open access to send SMTP traffic to anywhere in the world then that's a problem. Spam costs billions a year. Don't be a dirty spammer, and don't use companies that make being a dirty spammer easy.

Re: Sendmail issue
by Anonymous Monk on Aug 08, 2014 at 12:21 UTC

    Without getting into the details of sendmail - is there some reason you aren't using one of the many modules available for this task? For example, Mail::Sender - see also How do I send email?

Re: Sendmail issue
by bulrush (Scribe) on Aug 09, 2014 at 11:32 UTC
    Hi OP,

    I also have Comcast and what I've noticed is their SMTP server is sometimes busy, even when I use Thunderbird as my email client on Win 7 and 8. Typically it takes me 20-30 seconds just for TB to log on to the SMTP server when I send an email. Your SMTP log says "operation timed out" and this would be consistent with Comcast SMTP servers. Try again in a few hours.

    Do you still have the problem? Also check that you are using the right port. I think they use a different port to prevent spam.

    Also increase your timeout to 60 seconds.

    Perl 5.8.8 on Redhat Linux RHEL 5.5.56 (64-bit)
Re: Sendmail issue
by sances (Initiate) on Aug 12, 2014 at 12:51 UTC

    Hi, I used to do a similar thing, starting over ten years ago, with comcast as my ISP at home. I had a script that would notes to about 200 or so people from a place I used to work at. About 4-5 years ago it stopped working. After trying darn near everything, I did find out that comcast blocked outgoing mail like this on purpose. I assume they still do. It was supposedly a spam issue with them.

    Really. But I'm not spamming, so what do I do? Networking and SMTP is outside my area of competence. My mail client works - apple mail, thunderbird, eudora all worked to send mail, so I'm thinking wtf? I changed over to using an applescript thing that sends my notes out through apple mail to each member in a group I set up in Contacts. It's ugly and it's awful, because working in apple script is like learning martian. I still don't get it. But once it worked I stopped caring how it looked, since I wasn't at work.

    All this might not make sense on first reading, but it's true. I think you end up bypassing the comcast smtp facility and instead use comcast merely to connect to, say, a google or apple account (I do either, both work).

    So long story short - maybe you write a mail client and get around this, or use an existing mail client. But if you figure this out I will be interested to see how it worked.

    Good luck to you