Unable to send mail from linux command line

Ubuntu / 8.10 desktop edition
January 11, 2010 at 12:11:51
Specs: Linux/Ubuntu
hi all i am absolutely new to linux /ubuntu.
How to send a mail from command line?
I used the below.The command seems to right.
echo "hi buddy " | mailx -s "Could you please help me" XXXXX@gmail.com
But i am not getting the mail in my gmail inbox when i check it.
Do i need to set something else in my terminal?
I tried to ask google.
But being a beginner i hardly understand the technical jargons and don't get my exact reply.

Could you please help?

See More: Unable to send mail from linux command line

Report •

January 11, 2010 at 12:29:26
You may have to configure the MTA (Mail Transport Agent) to use the providers mail server for sending mails.
So your MTA authenticates at the providers mail server, sends the file, to that server and the server sends the mail to it's final destination.

Report •

January 11, 2010 at 12:46:03
Thanks Paulsep for the prompt reply.
But could you please say how to configure this MTA?
What commands to use for this or which site to refer for this?
I would highly appreciate if you could let me know the steps.

Report •

January 11, 2010 at 13:08:01
So that you're using mailx, I assume Postfix is also installed as MTA.
You may check this by using the following command in a shell:
rpm -qa postfix

Also check whether postfix is running:
ps aux | grep postfix

Read the man pages about postfix or visit

Report •

Related Solutions

January 11, 2010 at 15:27:46
I just finished setting up postfix following the steps given in
Still the mail is not working.
I have some confusion in the steps.
1.when it says server1.example.com can i put server1.gmail.com?
2. Can i enter any word of my choice when it prompts me to enter passphrase?
3.As the line says
"If you want to use port 587 as the submission port for SMTP mail rather than 25 (many ISPs block port 25), you will need to edit /etc/postfix/master.cf to uncomment the relevant line for port 587 there."
I don't find the no 587 anywhere commented neither 25.
4. As per the first step of troubleshooting do i need to set the Configure saslauthd to Default?

Report •

January 12, 2010 at 10:23:15
1.So can i put the name like Geeking4awhile-laptop if that is my laptop/computer or this needs to be some IP/localhost?

2.There is a step in https://help.ubuntu.com/community/Postfix
Generate certificates to be used for TLS encryption and/or certificate Authentication:
here there are two commands which ask me country name passphrase,state name...etc.
the commands are
openssl req -new -key smtpd.key -x509 -days 3650 -out smtpd.crt # has prompts
openssl req -new -x509 -extensions v3_ca -keyout cakey.pem -out cacert.pem -days 3650 # has prompts

ISP's mail server :could you please give an example of this in layman's term or what you would keep if u needed to.
Mean while i am trying to locate that.

THANKS for such valuble informations buddy!

Report •

January 12, 2010 at 11:29:36
In your /etc/postfix/main.cf, you have to add a line like this:

relayhost = smtp.gmail.com

You have to change the relayhost to match your needs.
So e.g. the mailserver for outgoing mails of GMX is mail.gmx.net.

Also add the following lines to your main.cf file:
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

NOTICE: The whitespaces are necessary at both sides of the equal sign.

The password, needed to authenticate at your providers mailserver must be configured in the /etc/postfix/sasl_passwd file.
smtp.gmail.com your_password

Report •

January 12, 2010 at 13:47:52
Hi Paulsep i added the line with whitespace
relayhost = smtp.gmail.com
this field was previously blank
smtp_sasl_auth_enable = yes :this line was already there.

smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd : this line i have not added yet.
Was wondering can i make it work without password first.
But still it does not work it says Unable to connect to remote host connection timed out when i use telnet smtp.gmail.com/telnet smtp.gmail.com 25

Report •

January 12, 2010 at 14:23:23
The command to telnet the mailserver is:
telnet smtp.gmail.com 25

Should work !!!

Report •

January 12, 2010 at 14:24:44
it seems that i have to also add smtp.gmail.com in the line below before the relayhost?
mydestination = server1.example.com, example.com, localhost.example.com, localhost

Report •

January 12, 2010 at 14:27:24
i had used the command you said
that could not connect.

Report •

January 12, 2010 at 14:32:16
mydestination looks like this:

mydomain = your_local_domain_name.com
myorigin = $mydomain
mydestination = $myhostname, localhost, $mydomain

Report •

January 14, 2010 at 14:52:45
well i got my host name /domain name by going to /etc/resolv.conf
Hence exactly i made the line as below
mydestination = asianetindia.com
myhostname = asianetindia.com

i have also tried my destination gmail.com
It did not work

I tried with relay host = asianetindia.com as well

Nothing did work :-(

which of the following lines i need to modify/add my values while reconfiguring the postfix in the first step?(In case i am doing something wrong....)

General type of mail configuration: Internet Site

NONE doesn't appear to be requested in current config

System mail name: asianetindia.com

Root and postmaster mail recipient: <admin_user_name>

Other destinations for mail: server1.example.com, example.com, localhost.example.com, localhost

Force synchronous updates on mail queue?: No

Local networks:

Yes doesn't appear to be requested in current config

Mialbox size limit (bytes): 0

Local address extension character: +

Internet protocols to use: all

Should i put my system name in the following line?
Root and postmaster mail recipient:

May be i have to reconfigure the postfix file from the beginning and get back to you guys.

Report •

January 14, 2010 at 15:40:41
Things you have to configure in the
Postfix configuration files:

# START main.cf
myhostname = your_machine_name.your_domain # your machine name is normally listed in the /etc/hosts file
mydomain = your_domain # if myhostname is e.g. pc1.homedomain.com, mydomain is homedomain.com
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain
mynetworks =, # if your local network is ( Otherwise make changes to match your needs.
relay_domains = $mydomain
mailbox_size_limit = 0 # for no limits
message_size_limit = 0 # for no limits
transport_maps = hash:/etc/postfix/transport
smtpd_helo_required = yes
disable_vrfy_command = yes
opt_delay_warning_time = 1
# recipient_delimiter = +
relayhost = smtp.gmail.com
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = /etc/postfix/sasl_passwd
smtp_sasl_security_options =
unverified_recipient_reject_code = 550
unknown_local_recipient_reject_code = 550
smtp_delay_reject = no
strict_rfc821_envelope = yes
smtpd_banner = $myhostname NO UCE ESMTP
smtpd_client_restrictions =
smtpd_helo_restrictions =
smtpd_sender_restrictions =
smtpd_recipient_restrictions =
smtpd_data_restrictions =
inet_protocols = all
inet_interfaces = all

# END main.cf

# START master.cf
# A lot of comments
# then the first smtp entry
smtp inet n - n - - smtpd
-o smtp_data_done_timeout=1200
-o receive_override_options=no_address_mappings
pickup fifo n - n 60 1 pickup
-o receive_override_options=no_header_body_checks
# the rest should be ok so far.
# END master.cf

# START transport
# many comments
# then at the end, add the following lines
your_domain_name :
.your_domain_name :
* smtp:smtp.gmail.com
# change the your_domain by your domain, configured at your system
# the fist 2 entries do deliver mails to local recipients
# the * smtp:smtp.gmail.com delivers mails to none local recipients
# END transport

# START sasl_passwd
smtp.gmail.com your_account_login_name:your_account_password
# END sasl_passwd

Report •

January 17, 2010 at 00:17:37
is it through above lines i would use google's mailing service to email.
What about upstandingnetizen's view that smtp.gmail.com should not be there in relayhost?

where this transport and sasl_passwd file would be found?

Report •

January 17, 2010 at 03:32:40
Transport and sasl_passwd is normally located in the /etc/postfix/

Report •

January 18, 2010 at 09:44:02
The mail host for asianetindia.com is asianetindia.com is smtp.asianetindia.com.
You have to use mail address and password to authenticate.
Mailserver, email address and password must be stored in sasl_passwd in this form:
smtp.asianetindia.com youraccount@asianetindia.com:youpassword

Report •

Ask Question