sendmail from perl
I want to be able to send an e-mail (via sendmail) from a perl/cgi script. I cannot get this to work. Any help would be appreciated.
iMac, Mac OS X (10.7.5)
I want to be able to send an e-mail (via sendmail) from a perl/cgi script. I cannot get this to work. Any help would be appreciated.
iMac, Mac OS X (10.7.5)
What specific problems are you having. It isn't easy getting sendmail to work.
An alternative to sendmail is SendEmail. See: http://caspian.dotconf.net/menu/Software/SendEmail/
SendEmail is a lightweight, command line SMTP email client. If you have the need to send email from a command line, this free program is perfect: simple to use and feature rich. It was designed to be used in bash scripts, batch files, Perl programs and web sites, but is quite adaptable and will likely meet your requirements. SendEmail is written in Perl and is unique in that it requires NO MODULES. It has an intuitive and flexible set of command-line options, making it very easy to learn and use.
Easier to use than sendmail.
Thanks for that link. Here is another quote from that site:
Why not use sendmail?
Sendmail is a large and complex mail server. Installing this kind of mail software on servers (unless it's a mail server) is more of a security risk than it's worth. Not to mention it can be a real pain messing with configuration files and such. Systems need another simpler way to send email from the command prompt, and sendEmail provides this functionality. Its a simple, direct way to send email without the overhead of other conventional email software.
I haven't used SendEmail, but I am definitely going to try it out. I just happen to have one project in need of this.
Sorry for the lack of detail. Here goes:
This is the perl script:
#!/usr/bin/perl -w use strict;
my $sendmail = "/usr/sbin/sendmail -t";
my $subject = "SUBJECT: Test e-mail sent from a Perl script.\n";
my $content = "This test appears to be successful!";
my $to = "rjklaus\@cox.net\n";
my $send_to = "TO:myemail\@isp\n";
my $send_from = "FROM:myemail\@ispt\n";
open(FILE, "|/usr/sbin/sendmail -t") or print "Cannot open FILE.\n";
print FILE $send_to;
print FILE $send_from;
print FILE $subject;
print FILE "Content-type: text/plain\n\n";
print FILE $content;
close(FILE);
The script executes with out error, and you can step through with the debugger without a problem. But.. no mail is sent.
And here is what is in the mail.log file:
841 Sep 25 10:37:43 Ray-Klauss-iMac postfix/master[2345]: daemon started -- version 2.8.4, configuration /etc/postfix
842 Sep 25 10:37:43 Ray-Klauss-iMac postfix/qmgr[2347]: 038D38946D67: from=<rjklaus@Ray-Klauss-iMac.local>, size=357, nrcpt=1 (queue active)
843 Sep 25 10:37:43 Ray-Klauss-iMac postfix/qmgr[2347]: 1321E894C2CA: from=<rjklaus@Ray-Klauss-iMac.local>, size=382, nrcpt=1 (queue active)
844 Sep 25 10:37:43 Ray-Klauss-iMac postfix/qmgr[2347]: 159818959A03: from=<rjklaus@cox.net>, size=286, nrcpt=1 (queue active)
845 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 21A0F8946918: from=<rjklaus@Ray-Klauss-iMac.local>, size=363, nrcpt=1 (queue active)
846 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 22237894C5C8: from=<rjklaus@Ray-Klauss-iMac.local>, size=322, nrcpt=1 (queue active)
847 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 32E81894AB4D: from=<rjklaus@Ray-Klauss-iMac.local>, size=477, nrcpt=1 (queue active)
848 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 342A38956FC0: from=<rjklaus@Ray-Klauss-iMac.local>, size=388, nrcpt=1 (queue active)
849 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 3A72B89571BA: from=<rjklaus@Ray-Klauss-iMac.local>, size=388, nrcpt=1 (queue active)
850 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 3DE078946AE4: from=<rjklaus@Ray-Klauss-iMac.local>, size=363, nrcpt=1 (queue active)
851 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 3F3168946C14: from=<rjklaus@Ray-Klauss-iMac.local>, size=357, nrcpt=1 (queue active)
852 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 4B3FD894ABD9: from=<rjklaus@Ray-Klauss-iMac.local>, size=477, nrcpt=1 (queue active)
853 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 6184E8956B59: from=<rjklaus@Ray-Klauss-iMac.local>, size=317, nrcpt=1 (queue active)
854 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: 9DF25894C672: from=<rjklaus@Ray-Klauss-iMac.local>, size=322, nrcpt=1 (queue active)
855 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: A6481895634B: from=<rjklaus@Ray-Klauss-iMac.local>, size=388, nrcpt=1 (queue active)
856 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: AD1CD89565A6: from=<rjklaus@Ray-Klauss-iMac.local>, size=388, nrcpt=1 (queue active)
857 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: ADB41894C528: from=<rjklaus@Ray-Klauss-iMac.local>, size=322, nrcpt=1 (queue active)
858 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: CD7BD895F646: from=<rjklaus@Ray-Klauss-iMac.local>, size=388, nrcpt=1 (queue active)
859 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: CF1E5895643B: from=<rjklaus@Ray-Klauss-iMac.local>, size=388, nrcpt=1 (queue active)
860 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: E56D589472DD: from=<rjklaus@Ray-Klauss-iMac.local>, size=300, nrcpt=1 (queue active)
861 Sep 25 10:37:44 Ray-Klauss-iMac postfix/pickup[2346]: F2329895FD1C: uid=501 from=<rjklaus>
862 Sep 25 10:37:44 Ray-Klauss-iMac postfix/cleanup[2348]: F2329895FD1C: message-id=<20130925173744.F2329895FD1C@Ray-Klauss-iMac.local>
863 Sep 25 10:37:44 Ray-Klauss-iMac postfix/qmgr[2347]: F2329895FD1C: from=<rjklaus@Ray-Klauss-
iMac.local>, size=388, nrcpt=1 (queue active)
I hope this helps. I am totally frustrated.
The best way to debug sendmail is to create a little text e-mail message like this:
from: me@mydomain.com
to: me2@mydomain.com
subject: Testing
This is a test
And send it using:
cat test.txt | sendmail -oi me2@mydomain.com
If you have a local e-mail server, sendmail will work with that pretty easily. Trying to send e-mail from your local machine to the outside world requires a bit more work. See Tony's post or dig into the mysteries of sendmail SMTP routing.
If you do a simple sendmail from the command line does it work?
You might have a sendmail problem and not a perl/sendmail problem.
sendmail from perl