How to send an email within a script???
Basically, I want to create a script which send an email if any of the condition is not met. So, it's like an alarm. So now, my problem is how to open an email to send a message from a script. Could anybody give me an idea...
I have tried the following commands but to no avail. There was no error when I run the script, but I didn't receive any email. Is there anything I need to setup beforehand? Thanks for your prompt reply...
mail -s "john" firstname.lastname@example.org < hello.txt
cat hello.txt | mailx -s Subject email@example.com
My Distribution is Fedora C5.
You need to give more information. What error messages are you getting (if at all), when you try that? Both of those commands should work, if everything is set up properly.
You need sendmail working to use those. Are you sure you have sendmail installed and working? rpm -q sendmail will tell you if it's installed. It will give you the name and version number, or if it's not installed, it'll say package sendmail is not installed.
If it's not installed, install it by doing (as root), yum install sendmail, then follow the following steps once it's installed.
If it's installed, you have to check that it's actually started up. As root, type service sendmail status.
I think it should say Checking for service sendmail: [OK], if it's working properly. If it's not running, you can start it with service sendmail start, and to ensure it starts when you boot up next time, then type chkconfig sendmail on.
If it's installed, and running properly, then the problem could very well be your ISP. Some ISP's block outgoing mail if it's not send through their SMTP server (SBC, for example, does that).
Probably the mail server consider the sender as spam, have you check the junk mail folder?
You'd use "mailx" under Solaris, "mail" under Linux. The redirections ("cat hello.txt | command" and "command < hello.txt") are in their effect equivalent. You don't absolutely need the sendmail *package*; e.g., qmail provides a perfect replacement (and claims to be secure).
It's quite possible that your MTA isn't configured correctly. If so, the 'mail' program could run without errors, but the message could still fail to send and you'd see errors in a logfile somewhere in /var/log/*
Unfortunately I don't even know what mta fedora uses by default, let alone how to tweak it.
This is what I got I executed the commands checking for the status of the sendmail. It seems it is installed and running. Is there any work around on how to unblock outgoing mail if it's not send through the SMTP server? Do I need to set up my email using my ISP pop server...Thanks for your prompt reply...
[root@john ~]# rpm -q sendmail
[root@john ~]# service sendmail status
sendmail (pid 2938 2305 2301 2296) is running...
The following is what I got ferom the maillog.Can you see anything wrong with the log? How could I configure my MTA. Could you give me an idea...Sori m pretty much novice with Linux system... Thanks for your prompt reply...
Aug 28 20:42:52 john sendmail: k7T0gqLA002935: firstname.lastname@example.org, ctladdr=johnsanty (500/500), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30054, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (k7T0gq6H002936 Message accepted for delivery)
I'm not sure if this is related. I tried to set up my Evolution email using my ISP pop and smtp servers then i got an error message when I tried to send an email to my yahoo account. The error message is the following:
"Error while performing operation.
MAIL FROM command failed: Must issue a STARTTLS command first"
Now, i tried to search for this error and one person suggested that I need to enable the TLS..how could I enable my TLS...? Thanks for your help....
how do you write your script in sending email? I write mine in this format
$to = "email@example.com";
$subject = "test mail";
$message = "test message";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $subject, $message, $headers);
It seems the question shifted to whether you can send e-mail at all, whether from a script or outside? You could try mailing directly from the shell, i.e.,
Requiring STARTTLS probably means someone insist on encryption. Not sure who, maybe your ISP? It's not your e-mail provider yahoo, as the session below shows. You can manually run SMTP sessions, and it can help figuring out what the problem is. So starting with the e-mail address you provided above, I did the following. What I typed is bold.
Now I don't know what your sendmail does -- maybe it relays all outgoing mail through your ISP who insists on encryption? Or it talks directly to the destination MTA (e.g., mx1.mail.yahoo.com)? Try to pinpoint the problem. If it's your sendmail configuration, there should be a number of people on this forum who can help you.
From the log message the OP posted, it looks like sendmail may be trying to send directly to the destination mail server (I'm guessing this because it says it's using 127.0.0.1 as a relay). If that's the case (I'm not really sure that it is), the destination could be rejecting the mail as spam because it comes from a suspicious dynamic address, or your isp could be filtering outbound connections to port 25.
If you can figure out how to get sendmail to forward everything to your isp's smtp server that might help. in the debian configs that is called a "smarthost"
Can you try to telnet to mx1.mail.yahoo.com, port 25? If you get to the 220 message, at least you know your ISP isn't filtering those connections.
Also, you could look in the mail log (where you found "relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (k7T0gq6H002936 Message accepted for delivery)") and see if you can locate further down an entry when sendmail actually attempts that delivery? It might be informative.
Actually, I tried to send mail directly from command line but I got the same result. Now I tried the following:
telnet mx1.mail.yahoo.com 25
And I got the following, it seems that it is not connecting at all.
[johnsanty@babe1 ~]$ telnet mx1.mail.yahoo.com 25
telnet: connect to address 188.8.131.52: Connection timed out
telnet: connect to address 184.108.40.206: Connection timed out
telnet: connect to address 220.127.116.11: Connection timed out
In the maillog, I got the following. I'm not sure if this message conveys that the message has been sent. Can you confirm?:
Aug 29 22:58:23 babe1 sendmail: k7U2wNiM003236: from=johnsanty, size=60, class=0, nrcpts=1, msgid=<200608300258.k7U2wNiM003236@babe1>, relay=johnsanty@localhost
Aug 29 22:58:23 babe1 sendmail: k7U2wNtV003237: from=<johnsanty@babe1>, size=324, class=0, nrcpts=1, msgid=<200608300258.k7U2wNiM003236@babe1>, proto=ESMTP, daemon=MTA, relay=localhost.localdomain [127.0.0.1]
Aug 29 22:58:23 babe1 sendmail: k7U2wNiM003236: firstname.lastname@example.org, ctladdr=johnsanty (500/500), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30060, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (k7U2wNtV003237 Message accepted for delivery)
However,in the /var/spool/mail, I got the following several of them since I have attempted many time to send an email. Does it look like a problem with my configuration or with yahoo? Also, I tried sending an email to my hotmail account and i got the same thing. Do you have any idea.....i dont know if it is my sendmail configuration or not. Do you know by any chance on how to configure the senmail? Thanks for your prompt reply...
** THIS IS A WARNING MESSAGE ONLY **
** YOU DO NOT NEED TO RESEND YOUR MESSAGE **
The original message was received at Mon, 28 Aug 2006 21:27:23 -0400
from localhost.localdomain [127.0.0.1]
----- Transcript of session follows -----
<email@example.com>... Deferred: Connection timed out with mx4.mail.yahoo.com.
Warning: message still undelivered after 4 hours
Will keep trying until message is 5 days old
Reporting-MTA: dns; babe1
Arrival-Date: Mon, 28 Aug 2006 21:27:23 -0400
Final-Recipient: RFC822; firstname.lastname@example.org
Remote-MTA: DNS; mx4.mail.yahoo.com
Last-Attempt-Date: Tue, 29 Aug 2006 22:43:56 -0400
Will-Retry-Until: Sat, 2 Sep 2006 21:27:23 -0400
Received: from babe1 (localhost.localdomain [127.0.0.1])
by babe1 (8.13.5/8.13.5) with ESMTP id k7T1RNvY002973
for <email@example.com>; Mon, 28 Aug 2006 21:27:23 -0400
Received: (from btamayo@localhost)
by babe1 (8.13.5/8.13.5/Submit) id k7T1RNVv002972
for firstname.lastname@example.org; Mon, 28 Aug 2006 21:27:23 -0400
Date: Mon, 28 Aug 2006 21:27:23 -0400
From: John Santy <johnsanty@babe1>
From MAILER-DAEMON@babe1 Tue Aug 29 22:47:57 2006
Received: from localhost (localhost)
by babe1 (8.13.5/8.13.5) id k7U2BsfD002300;
Tue, 29 Aug 2006 22:47:57 -0400
Date: Tue, 29 Aug 2006 22:47:57 -0400
From: Mail Delivery Subsystem <MAILER-DAEMON@babe1>
Content-Type: multipart/report; report-type=delivery-status;
Subject: Warning: could not send message for past 4 hours
Auto-Submitted: auto-generated (warning-timeout)
This is a MIME-encapsulated message
I'm not using sendmail, so I'm not the right person to ask about its configuration. Many years ago I heard people say getting it right is close to black magic. But hopefully things got better. And there is documentation out there. A quick Google search turned up http://sendmail.org and you may particularly want to study the section about configuration, http://www.sendmail.org/m4/readme.html :study:.
If after reading you still have questions, you may want to come back. Maybe even post a new question.
Ok, so to fix sendmail to forward through your ISP, here's what you need to do (all as root, of course):
First, you need to open up sendmail's config file (actually it's the master control file, but no reason to nitpick). If I remember correctly, it's /etc/mail/sendmail.mc
Look for a line that says something like "dnl define(`SMART_HOST', `smtp:smtp.yourisp.net')dnl."
If it doesn't say smtp, that's ok. smtp is the default if it's not specified. Change whatever address is in there to your isp's smtp address, and then delete the dnl at the beginning of the line (but not at the end). Be sure not to change any of the quotes, etc. It uses specific types of quotes, and screws up if the wrong kind are used.
Once you've done that, assuming your current directory is /etc/mail, type make. That should generate a new config file for you. If it didn't (you'll know if it says "Nothing to be done for all"), then you have to do it yourself. "m4 sendmail.mc > sendmail.cf" should do it. Then type service sendmail restart, and you should be good to go.
Now this assumes that you're ISP doesn't require you to login to the smtp server, or use a secure connection. I never was able to figure out how to get it working in that case. I just found another smtp server provided by my ISP that didn't require login.
|All times are GMT -5. The time now is 10:48 AM.|