LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-12-2015, 01:53 PM   #1
kc5hwb
Member
 
Registered: Jun 2001
Location: Grapevine, Texas
Distribution: Ubuntu 14.04, CentOS 7
Posts: 102

Rep: Reputation: 15
Sending Mail from Command Line


I searched the forums for my title and I am not finding exactly what I am looking for. I am not using a program to send mail, such as Thunderbird or whatever. I simply want to be able to send mail from my Ubuntu 14.04 DESKTOP version for logging. I use a program called Logwatch (used alot in RHEL or CentOS) to monitor the server itself. The program sends mail to the root user account on the machine, which I can check and see, and within the program conf file, I can add an external email address, but it never sends.

I'm familiar with the SMTP concept of sending mail, outgoing mail server authentication, etc. I don't care to run this box as an SMTP server, but I understand that I need some sort of SMTP or MTA program to send mail into the real world. I tried Postfix but couldn't get that to work, and the Logwatch program wants to use sendmail, so I installed that but I am having the same issue. I am sure it is a step I am missing.

I also can't figure out how to get the 'mail' cmd from Terminal to work. I use this command:
Code:
mail -s "test" | /usr/sbin/mail myemail@domain.com
it follows through the subject, CC, body, but when I try to hit either . or CTRL-D, it never sends the email, in fact is does nothing.

I also tried sendmail with this command:
Code:
sendmail -v my@email.com < /dev/null
I was just trying to send a test email. It logs into my SMTP mail server, which I already configured, and it tells me to type out the mail, then end with a "." by itself on a single line. I try this and it just sits there.

I am missing SOMETHING when trying to actually send the mail. I can get it written with subject and body, connected, but it never sends and I am probably missing a / or something.

I did find and follow these instructions, but it still isn't working with sendmail. If I need to go back to Postfix, I can do that, I don't honestly care what I use, I just want some programs such as Logwatch to be able to email me.
http://stackoverflow.com/questions/1...mail-on-ubuntu
 
Old 05-12-2015, 02:10 PM   #2
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
Code:
mail -s "test" | /usr/sbin/mail myemail@domain.com < /dev/null
sendmail syntax may be slightly different.

Last edited by Habitual; 05-12-2015 at 02:12 PM.
 
Old 05-12-2015, 02:13 PM   #3
kc5hwb
Member
 
Registered: Jun 2001
Location: Grapevine, Texas
Distribution: Ubuntu 14.04, CentOS 7
Posts: 102

Original Poster
Rep: Reputation: 15
Code:
-bash: /usr/sbin/mail: No such file or directory
 
Old 05-12-2015, 02:26 PM   #4
kc5hwb
Member
 
Registered: Jun 2001
Location: Grapevine, Texas
Distribution: Ubuntu 14.04, CentOS 7
Posts: 102

Original Poster
Rep: Reputation: 15
Trying this command but it is taking a while
Code:
mail -s "test" | /usr/sbin/sendmail my@email.com < /dev/null
 
Old 05-12-2015, 03:11 PM   #5
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
This is from the mailutils package to send mail from a trusted host.
using this template:
Code:
mail -s "test" | /usr/sbin/mail myemail@domain.com < /dev/null
http://tecadmin.net/ways-to-send-ema...-command-line/ suggests you should expect success, else check /var/log/<something> for clues.

Use
Code:
sudo apt-get install mailutils
to install it. It shouldn't conflict with sendmail in any way using
Code:
mail -s "test" | /usr/sbin/mail myemail@domain.com < /dev/null
after that install.

Sorry.

Last edited by Habitual; 05-12-2015 at 03:13 PM.
 
Old 05-12-2015, 03:34 PM   #6
kc5hwb
Member
 
Registered: Jun 2001
Location: Grapevine, Texas
Distribution: Ubuntu 14.04, CentOS 7
Posts: 102

Original Poster
Rep: Reputation: 15
No need to apologize, thanks for the help.

mailutils is already installed, has been for a while. I just installed sendmail today, and you are right, it didn't seem to interfere with mailutils.

I've googled and found many similar strings to the original one you posted, but they simply do not send mail. That is my problem. I assume I have something wrong somewhere because this string would work, according to numerous websites.
 
Old 05-12-2015, 06:42 PM   #7
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
de-install sendmail and see if this command then works?
You should also be able send mail to yourself on the localhost using
Code:
mail -s "test" $(whoami) < /dev/null
then use "mail" to read it.
 
Old 05-13-2015, 06:13 AM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
A couple of examples

Code:
# nc -C localhost 25 << EOF
HELO localhost
MAIL FROM: root@localhost
RCPT TO: root@localhost
DATA
From: chris <chris@localhost>
To: me <chris@localhost>
Subject: nc email demo

Test Body of email.
.
QUIT
EOF
Code:
(uname -n)|mailx -s "Test email" chris@x.y.com

Last edited by chrism01; 05-13-2015 at 06:15 AM. Reason: typo
 
Old 05-13-2015, 08:37 AM   #9
kc5hwb
Member
 
Registered: Jun 2001
Location: Grapevine, Texas
Distribution: Ubuntu 14.04, CentOS 7
Posts: 102

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Habitual View Post
de-install sendmail and see if this command then works?
You should also be able send mail to yourself on the localhost using
Code:
mail -s "test" $(whoami) < /dev/null
then use "mail" to read it.

jape@samson:~$ mail -s "test" $(whoami) < /dev/null
mail: Null message body; hope that's ok
.

Running this command puts me back into the mail options where I can write out a body of an email, but can't send it. This is after removing sendmail.
 
Old 05-13-2015, 08:41 AM   #10
kc5hwb
Member
 
Registered: Jun 2001
Location: Grapevine, Texas
Distribution: Ubuntu 14.04, CentOS 7
Posts: 102

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
A couple of examples

Code:
# nc -C localhost 25 << EOF
HELO localhost
MAIL FROM: root@localhost
RCPT TO: root@localhost
DATA
From: chris <chris@localhost>
To: me <chris@localhost>
Subject: nc email demo

Test Body of email.
.
QUIT
EOF
Code:
(uname -n)|mailx -s "Test email" chris@x.y.com
Running the first command as root puts me into a > prompt. (a "do" prompt?)

Running the (uname -n) command acts like it is sending email, but it never shows up in my inbox.
 
Old 05-14-2015, 11:47 AM   #11
kc5hwb
Member
 
Registered: Jun 2001
Location: Grapevine, Texas
Distribution: Ubuntu 14.04, CentOS 7
Posts: 102

Original Poster
Rep: Reputation: 15
I did some Googling and found a good article for using Postfix on Ubuntu and using Sendmail on CentOS.

I have 2 boxes running at the house, with plans for more soon, so I would hesitate to setup both boxes with a FQDN, but I guess I could set one up and just use it to send mail from the other boxes too. Not sure what I want to do yet, though. My other option is to just send everything through my Gmail account, but I have read online that they don't give out certificates for that anymore, so I am not sure I can get that to work.

Still researching...
 
Old 05-14-2015, 11:54 AM   #12
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,159
Blog Entries: 10

Rep: Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968Reputation: 1968
I use postfix everywhere, both Ubu and CentOS.
 
Old 05-14-2015, 12:30 PM   #13
kc5hwb
Member
 
Registered: Jun 2001
Location: Grapevine, Texas
Distribution: Ubuntu 14.04, CentOS 7
Posts: 102

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Habitual View Post
I use postfix everywhere, both Ubu and CentOS.
I might try that also. CentOS comes with Sendmail installed and Logwatch wants to use Sendmail by default, but of course that can be changed. I just need something that will send email to my email address from Logwatch logs.
 
Old 05-15-2015, 09:29 AM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Have you checked /var/log/maillog at both ends ..?
Both my examples work on Centos 6 locally and would work to a remote mailserver IF it accepts remote emails from the src address.
 
Old 05-15-2015, 10:14 AM   #15
kc5hwb
Member
 
Registered: Jun 2001
Location: Grapevine, Texas
Distribution: Ubuntu 14.04, CentOS 7
Posts: 102

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
Have you checked /var/log/maillog at both ends ..?
Both my examples work on Centos 6 locally and would work to a remote mailserver IF it accepts remote emails from the src address.
I don't have a remote mail server setup. I was wanting to use postfix or sendmail as an SMTP server.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Sending mail from the command line hoholala Linux - Software 2 01-02-2014 10:07 PM
Sending mail from command line. alaios Linux - Software 8 03-07-2013 10:15 AM
Command line e-mail and NOT sending out malware nelson202tx Linux - Newbie 2 10-16-2010 03:36 AM
Sending mail from command line Geert86 Linux - Server 10 11-30-2009 01:04 PM
Sending mail from command line matiasquestions Linux - Software 5 01-22-2006 12:51 PM


All times are GMT -5. The time now is 02:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration