Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How To Send E-Mail On CentOS 7

Installing mailx

yum -y update
yum install -y mailx

We can now start sending e-mails using

create a symbolic link

ln -s /bin/mailx /bin/email

###Set an External SMTP Server to Relay E-Mails

vi /etc/mail.rc

edit

set smtp=smtps://smtp.gmail.com:465
set smtp-auth=login
set smtp-auth-user=USERNAME@YOURDOMAIN.COM
set smtp-auth-password=YOURPASSWORD
set ssl-verify=ignore
set nss-config-dir=/etc/pki/nssdb/

example usage :

echo "Your message" | mail -v -s "Message Subject" email@address
@ranjeetranjan

This comment has been minimized.

Copy link

@ranjeetranjan ranjeetranjan commented Aug 5, 2017

Thanks lot. It works for me.

@arunm8489

This comment has been minimized.

Copy link

@arunm8489 arunm8489 commented Sep 21, 2017

Iam getting this error.Pls help.....

[root@cent6rr authinfo]# echo "Your message" | mail -v -s "Message Subject" arunm8489@gmail.com
Resolving host smtp@gmail . . .Could not resolve host: smtp@gmail
"/root/dead.letter" 11/410
. . . message not sent.

@ocerecedo

This comment has been minimized.

Copy link

@ocerecedo ocerecedo commented Nov 3, 2017

echo "Your message" | mail -r "tucorreodelsmtp" -v -s "Message Subject" arunm8489@gmail.com

@picasso250

This comment has been minimized.

Copy link

@picasso250 picasso250 commented Dec 14, 2017

It Works! thx!

if you want it work with QQ mail
QQ企业邮箱

set from=994414615\@qq.com

不要忘记反斜杠

参考:
http://blog.csdn.net/cwg_1992/article/details/22661451

@samiraguiar

This comment has been minimized.

Copy link

@samiraguiar samiraguiar commented Mar 16, 2018

Thank you for this.

For servers that use port 587 you might need to change one line and add another:

set smtp=some.server.com:587 # change protocol here
set smtp-use-starttls        # add this

Also you may get a "550 Sender address is not allowed.", which implies you need to add another field:

set from="someuser@address(John Doe)"
@iurijacob

This comment has been minimized.

Copy link

@iurijacob iurijacob commented Apr 9, 2018

Just for general information, if you're getting the following error, you'll have to allow access of less secure apps in Google Account settings.

smtp-server: 534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=????????
smtp-server: 534-5.7.14 ????????????????????????????????????????????????????????????????????????????????????????
smtp-server: 534-5.7.14 ????????????????????????????????????????????????????????????????????????????????????????
smtp-server: 534-5.7.14 ????????????????????????????????????????????????????????????????????????????????????????
smtp-server: 534-5.7.14 ???????????> Please log in via your web browser and
smtp-server: 534-5.7.14 then try again.
smtp-server: 534-5.7.14  Learn more at
smtp-server: 534 5.7.14  https://support.google.com/mail/answer/78754 b2sm612744qtj.84 - gsmtp
@hectorr013

This comment has been minimized.

Copy link

@hectorr013 hectorr013 commented Apr 17, 2018

Thanks you!

@sTandon22

This comment has been minimized.

Copy link

@sTandon22 sTandon22 commented May 16, 2018

Getting below error -

Resolving host smtp.gmail.com . . . done.
Connecting to 74.125.24.109:465 . . .Connecting to 74.125.24.108:465 . . .Connecting to 2404:6800:4003:c03::6c:465 . . .could not connect: Network is unreachable
"/root/dead.letter" 10/253

Please help

@meenakommo64

This comment has been minimized.

Copy link

@meenakommo64 meenakommo64 commented Dec 24, 2018

It is not working , problem with this error, please let me know
Resolving host smtp.outlook.com . . . done.
Connecting to 40.97.127.146:465 . . .

@fernandobatels

This comment has been minimized.

Copy link

@fernandobatels fernandobatels commented Jan 14, 2019

Thanks you!

For configure the mailx on crond: https://unix.stackexchange.com/questions/290573/calling-mailx-from-crond

@A9HORA

This comment has been minimized.

Copy link

@A9HORA A9HORA commented Mar 29, 2019

Hello,
Below are my mail.rc files configurations and still I'm getting an error.

#SMTP Configuration
set smtp-use-starttls
set ssl-verify=ignore
set smtp-auth=login
set smtp=smtp://smtp_server_I_want_to_connect:587
set from="my_email_address"
set smtp-auth-user=my_email_address
set smtp-auth-password=my_password
set nss-config-dir=/etc/pki/nss

#Error.1

STARTTLS
220 2.0.0 SMTP server ready
Error initializing NSS: Unknown error -8015.
"/root/dead.letter" 11/324

after changing
set nss-config-dir=/etc/pki/nss -> set nss-config-dir=/etc/pki/nssdb

Error.2

220 2.0.0 SMTP server ready
Error in certificate: Peer's certificate issuer is not recognized.

Please help and thank you in advanced.

@Lywangwenbin

This comment has been minimized.

Copy link

@Lywangwenbin Lywangwenbin commented Jun 3, 2019

smtp-server: 550 5.8.1 Local user only.
"/root/dead.letter" 11/319
. . . message not sent.

if u get the same error, maybe try vim /etc/mail.rc and add a line, set from=youremail@address

@chsuren

This comment has been minimized.

Copy link

@chsuren chsuren commented Sep 3, 2019

It worked. Thank you.
I was using
set smtp=smtps://smtp.gmail.com:587
It got me error on handshake changed to
set smtp=smtps://smtp.gmail.com:465

@mitsiek

This comment has been minimized.

Copy link

@mitsiek mitsiek commented Mar 24, 2020

getting below error:

SSL/TLS handshake failed: Unknown error -5961.
"/root/dead.letter" 11/337
. . . message not sent.

@kingoamino

This comment has been minimized.

Copy link

@kingoamino kingoamino commented Apr 23, 2020

Getting below error -

Resolving host smtp.gmail.com . . . done.
Connecting to 74.125.24.109:465 . . .Connecting to 74.125.24.108:465 . . .Connecting to 2404:6800:4003:c03::6c:465 . . .could not connect: Network is unreachable
"/root/dead.letter" 10/253

Please help

if you are using the EC2 instance from aws, you must have an autorisation from aws to send emails! they dont allow peaple to send emails befor be certain that they are not a SPAMERS !!

@kingoamino

This comment has been minimized.

Copy link

@kingoamino kingoamino commented Apr 23, 2020

It is not working , problem with this error, please let me know
Resolving host smtp.outlook.com . . . done.
Connecting to 40.97.127.146:465 . . .

if you are using the EC2 instance from aws, you must have an autorisation from aws to send emails! they dont allow peaple to send emails befor be certain that they are not a SPAMERS !!

@adrianogarru

This comment has been minimized.

Copy link

@adrianogarru adrianogarru commented Jun 22, 2020

Thanks ilkereroglu for your sharing!

In my virtual instance, Linux CentOS 8 works perfectly, in case you want to configure a Gmail account with 2Factors enabled, it is needed to you the app password: error received:

535-5.7.8 Username and Password not accepted. Learn more at
smtp-server: 535-5.7.8 Username and Password not accepted. Learn more at
535 5.7.8 https://support.google.com/mail/?p=BadCredentials a22sm8057227wmj.9 - gsmtp
smtp-server: 535 5.7.8 https://support.google.com/mail/?p=BadCredentials a22sm8057227wmj.9 - gsmtp

Article to follow in Google Help Center.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.