LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 03-02-2011, 02:24 PM   #1
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Rep: Reputation: 28
How to send email from command line?


I'm looking for an easy way to send basic emails for the command line. I have tried configuring sendmail and mailx, but I have yet been able to receive a test email at my remote address.

I have read through a fair amount of "how to" on this but I am a little confused and obviously not doing something right.

My sendmail.mc file is as follows
Code:
divert(0)dnl
VERSIONID(`$Id: generic-linux.mc,v 8.1 1999/09/24 22:48:05 gshapiro Exp $')
OSTYPE(linux)dnl
DOMAIN(generic)dnl
MAILER(local)dnl
MAILER(smtp)dnl
When I try to send a test mail via
Code:
# mail -s "Hello world" myemail@gmail.com
test mail
EOT
I see
Code:
send-mail -i myemail@gmail.com
running in the process list for a while and then it goes away, but I never actually receive the email at my gmail account(I have also check the spam folder just in case). I have also tried sending the test email to my work email address, but that doesn't work either.

Any help would be great.
 
Old 03-02-2011, 02:30 PM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,184

Rep: Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584
try this test:

Code:
sendmail -v someemail@somewhere.com
some text
.
(press "period and then enter" to end)

Post output
 
Old 03-02-2011, 03:26 PM   #3
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
Quote:
Originally Posted by szboardstretcher View Post
try this test:

Code:
sendmail -v someemail@somewhere.com
some text
.
(press "period and then enter" to end)

Post output
So I tried your suggestion, here is the output.
Code:
~ # sendmail -v myemail@gmail.com
test mail2
.
myemail@gmail.com... Connecting to [127.0.0.1] via relay...
myemail@gmail.com... Deferred: Connection refused by [127.0.0.1]

Last edited by dbrazeau; 03-02-2011 at 03:30 PM.
 
Old 03-02-2011, 03:44 PM   #4
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
Here is my /var/log/maillog... thought it might also be useful.

Code:
sendmail[1342]: p235KOdl001342: to=myemail@gmail.com, ctladdr=root (0/0), delay=00:00:03, 
xdelay=00:00:00, mailer=relay, pri=30009, relay=[127.0.0.1] [127.0.0.1], dsn=4.0.0, 
stat=Deferred: Connection refused by [127.0.0.1]
 
Old 03-02-2011, 04:17 PM   #5
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,254

Rep: Reputation: 314Reputation: 314Reputation: 314Reputation: 314
For quick, simple mails I use perl program sendEmail.
 
Old 03-02-2011, 04:38 PM   #6
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
Quote:
Originally Posted by eSelix View Post
For quick, simple mails I use perl program sendEmail.
Thanks for your help.

I gave sendEmail a try but get this error:
Code:
sendEmail[5886]: ERROR => Connection attempt to localhost:25 failed: IO::Socket::INET: connect: Connection refused
I am eventually going setup smartd (smartmontools) to send SMART warning emails out, so I'm not sure if sendEmail would be sufficient anyway.
 
Old 03-02-2011, 04:57 PM   #7
Stephen Morgan
Member
 
Registered: Feb 2011
Location: England
Distribution: Slackware
Posts: 163

Rep: Reputation: 17
I'm only a moderately competent user but, although it was simple enough to setup fetchmail, procmail and mailx for receiving mail I never managed to get sendmail to work.

Are you just trying to send through a remote smtp server, like through the smtp at gmail or yahoo? Or are you trying to run a full mail server? If it's the first then I'd recommend ssmtp, which I got working in about five minutes, which is less time than it took me to fail with sendmail by a very long way.
 
Old 03-02-2011, 07:49 PM   #8
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
Quote:
Originally Posted by Stephen Morgan View Post
I'm only a moderately competent user but, although it was simple enough to setup fetchmail, procmail and mailx for receiving mail I never managed to get sendmail to work.

Are you just trying to send through a remote smtp server, like through the smtp at gmail or yahoo? Or are you trying to run a full mail server? If it's the first then I'd recommend ssmtp, which I got working in about five minutes, which is less time than it took me to fail with sendmail by a very long way.
I do not want to send my emails through a remote smtp server, since there is a good change my system will be running on a closed network. Maybe my issue is that I don't have a smtp server running locally. I though sendmail took care of that, but I may be wrong. What do I need to do to run the smtp server on my system?
 
Old 03-03-2011, 07:54 AM   #9
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,184

Rep: Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584
Quote:
Originally Posted by dbrazeau View Post
So I tried your suggestion, here is the output.
Code:
~ # sendmail -v myemail@gmail.com
test mail2
.
myemail@gmail.com... Connecting to [127.0.0.1] via relay...
myemail@gmail.com... Deferred: Connection refused by [127.0.0.1]
type

Code:
service sendmail start
 
Old 03-03-2011, 11:38 AM   #10
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
Quote:
Originally Posted by szboardstretcher View Post
type

Code:
service sendmail start
So do I really need the sendmail service running to only send emails? I seems like if all I want to do is send emails it could just invoke sendmail when I try to send an email rather than having it running always.
 
Old 03-03-2011, 11:48 AM   #11
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
Also how do I correctly setup my hostname and domain for sending out emails? Can I just use any domain I want?
 
Old 03-03-2011, 12:03 PM   #12
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
Ok, so I started up my sendmail service. I am currently using postfix for my sendmail server. It looks like it is trying to actually send the email to the gmail-smtp server now, but it keeps getting connection refused. (I also get connection refused when trying to send to my work email as well. Here is the output in the maillog.
Code:
postfix/pickup[1415]: 5789B374577: uid=0 from=<root>
postfix/cleanup[1538]: 5789B374577: message-id=<20110303174111.5789B374577@hostname.localdomain>
postfix/cleanup[1538]: warning: file system clock is 203 seconds ahead of local clock
postfix/cleanup[1538]: warning: resetting file time stamps - this hurts performance
postfix/qmgr[1416]: 5789B374577: from=<root@hostname.localdomain>, size=457, nrcpt=1 (queue active)
postfix/smtp[1540]: connect to gmail-smtp-in.l.google.com[74.125.155.27]:25: Connection refused
postfix/smtp[1540]: connect to alt1.gmail-smtp-in.l.google.com[74.125.65.27]:25: Connection refused
postfix/smtp[1540]: connect to alt2.gmail-smtp-in.l.google.com[74.125.45.27]:25: Connection refused
postfix/smtp[1540]: connect to alt3.gmail-smtp-in.l.google.com[74.125.115.27]:25: Connection refused
postfix/smtp[1540]: connect to alt4.gmail-smtp-in.l.google.com[74.125.77.27]:25: Connection refused
postfix/smtp[1540]: 5789B374577: to=<myemail@gmail.com>, relay=none, delay=0.42, delays=0.39/0.02/0.01/0, dsn=4.4.1, status=deferred (connect to alt4.gmail-smtp-in.l.google.com[74.125.77.27]:25: Connection refused)
 
Old 03-03-2011, 12:22 PM   #13
devUnix
Member
 
Registered: Oct 2010
Location: Bengaluru, India
Distribution: RHEL 5.1 on My PC, & SunOS / Sun Solaris, RHEL, SuSe, Debian, FreeBSD and other Linux flavors @ Work
Posts: 576

Rep: Reputation: 48
I have written a tutorial on mail and mutt programs which is on the top of my blog:

http://unix-linux-dev.blogspot.com/

You can view it directly by opening this webpage:

http://unix-linux-dev.blogspot.com/2...nix-linux.html

I suggest you to look at my tutorial which is a step-by-step guide to mail and mutt programs, however not technically in-depth, but still it serves a good kick-start.
 
Old 03-03-2011, 02:16 PM   #14
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
Quote:
Originally Posted by devUnix View Post
I have written a tutorial on mail and mutt programs which is on the top of my blog:

http://unix-linux-dev.blogspot.com/

You can view it directly by opening this webpage:

http://unix-linux-dev.blogspot.com/2...nix-linux.html

I suggest you to look at my tutorial which is a step-by-step guide to mail and mutt programs, however not technically in-depth, but still it serves a good kick-start.
Thanks for pointing me to your blog, but it doesn't look like it is going to help me much. I can't even get the "Basic usage of mail" to work and it doesn't seem to cover mail server/domain configuration (where I think my issue lies).
 
Old 03-03-2011, 07:27 PM   #15
dbrazeau
Member
 
Registered: Aug 2009
Distribution: Fedora, OpenSuse, DENX Embedded Linux
Posts: 178

Original Poster
Rep: Reputation: 28
bump... any more help?
 
  


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
Send email from command line markotitel Linux - Newbie 4 10-26-2009 08:41 AM
how to send email with attachments from the command line km4hr Linux - Software 1 09-18-2007 10:10 AM
send email from command line djionel82 Programming 6 11-29-2005 12:12 AM
trying to send internet email from a command line...is it possible rutman Linux - Newbie 8 06-26-2004 02:19 AM
Can Pine send an email without from the command line without.. rutman Linux - Newbie 2 06-11-2004 04:34 PM


All times are GMT -5. The time now is 08:07 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