LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Sending mail from command line. (https://www.linuxquestions.org/questions/linux-software-2/sending-mail-from-command-line-4175452915/)

alaios 03-06-2013 02:30 AM

Sending mail from command line.
 
Dear all,
I would like to learn how to be able to send me mails from the command line.

I have read a bit this guide:

http://www.simplehelp.net/2008/12/01...-command-line/

and it when I try
something like that

mail -s “Hello world” you@youremailid.com < textToSend.txt
the command line returns back, which means that the line is executed. but I do not receive any mails.

I am not sure what is causing that . perhaps send mail is not installed . Please try to help me with the next steps but it should be a solution that will not interfere with my normal mails or make my system vulnerable to the outside world. I just need the mail for sending mails to my account.

Regards
Alex

shivaa 03-06-2013 02:33 AM

Try:
Code:

~$ mailx -s “Hello world” someone@example.sample.com  < infile.txt

chrism01 03-06-2013 02:34 AM

Well, if you got no error or msgs, it probably sent it to your mail server service on the same box.
What is your MTA/SMTP server; probably sendmail or postfix I'd guess.
Check /var/log/maillog; also try
Code:

mailq -AC
mailq -Lq


alaios 03-06-2013 02:53 AM

Houston we have a problem
Code:

mailq -AC
postqueue: fatal: Queue report unavailable - mail system is down
user@host:~> mailq -Lq
postqueue: fatal: Queue report unavailable - mail system is down


fortran 03-06-2013 06:54 AM

The 'mailutils' is installed successfully or not?
Try on terminal
Code:

$ echo "mail-body" | mail -s "mail-subject" "receivers.address@linuxmail.com"
If it is sent and received successfully then you can try above command mentioned by shivaa

If you still get this error.
Uninstall and install postfix and try again.

TB0ne 03-06-2013 08:52 AM

Quote:

Originally Posted by pavi_kanetkar (Post 4905882)
The 'mailutils' is installed successfully or not?
Try on terminal
"$ echo "mail-body" | mail -s "mail-subject" "receivers.address@linuxmail.com"" If it is sent and received successfully then you can try above command mentioned by shivaa

Wrong. The mailutils are obviously installed, since the command RUNS, and the OP mentioned he was getting output in the log files. Mailx will ALSO fail, since it appears that a mail system hasn't be set up.
Quote:

If you still get this error. Uninstall and install postfix and try again.
Wrong. Postfix is only ONE mail system, and it may or may not even be in use, so giving advice before knowing what the OP has is counterproductive.


OP, in order for your system to send mail anywhere, you have to configure the mail system, and start it. It appears you haven't, or that the mail system you have is down. Are you using postfix or sendmail?? You can start them with either "/etc/init.d/postfix restart" or "/etc/init.d/sendmail restart". That will stop any running processes for those services, and start them back up again, and may correct your "mail system is down" problem.

Mailx *CAN* work without either of those, but it also needs configuration, in order to know which other mail server to send your message TO. If you're in a company environment, chances are you already have a mail server. So, configure your mail system to use it as a smart host...there are MANY guides to do this for both postfix or sendmail.
http://www.cyberciti.biz/faq/configu...-a-smart-host/
http://gopalthorve.com/install-postf...ure-smarthost/

The man page on the mailx command will tell you how to use either another IMAP or POP3 server to send your mail through:
http://linux.die.net/man/1/mailx

fortran 03-07-2013 01:51 AM

Sorry but no intention to put wrong information.
Once I got the same error.I kept the solution in my linux notes. I did following process and it was solved.
I was getting
Code:

mail postfix/postqueue[20397]: fatal: Queue report unavailable - mail system is down
When I installed the mailutils,the postfix was installed automatically. I did not install it.
I was not able to send mails using terminal or apache (php mail function)
I found it on one site to detect the error, it asked first what is the out put of
Code:

mailq -AC
same command (asked by chrism01)
It gave me
Code:

mail postfix/postqueue[20397]: fatal: Queue report unavailable - mail system is down
The solution was there, Uninstall and install postfix. I did the same and then I type
Code:

mailq -AC
Now this time it gave me
Code:

Mail queue is empty
and I was able to send mail using
Code:

$ echo "mail-body" | mail -s "mail-subject" "receivers.address@linuxmail.com"
It looks like the error is same so I gave this solution, i didn't mean any harm (to OP's system).

alaios 03-07-2013 07:37 AM

Hi it was fixed by starting postfix. could you please let me know if I have to apply any specific security settings?

Regards
Alex

TB0ne 03-07-2013 09:15 AM

Quote:

Originally Posted by alaios (Post 4906665)
Hi it was fixed by starting postfix. could you please let me know if I have to apply any specific security settings?

There's no way we can answer that, since we don't know what the security requirements are of your organization, where the server is located (facing the internet? Internal only?), or what you're trying to do.


All times are GMT -5. The time now is 05:34 PM.