Skip to content

Instantly share code, notes, and snippets.

@ilkereroglu
Created September 22, 2015 21:53
Show Gist options
  • Save ilkereroglu/aa6c868153d1c5d57cd8 to your computer and use it in GitHub Desktop.
Save ilkereroglu/aa6c868153d1c5d57cd8 to your computer and use it in GitHub Desktop.
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
@A9HORA
Copy link

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
Copy link

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
Copy link

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
Copy link

mitsiek commented Mar 24, 2020

getting below error:

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

@kingoamino
Copy link

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
Copy link

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
Copy link

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.

@Aliya55
Copy link

Aliya55 commented Feb 8, 2021

I'm getting this error. Can anyone help?

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

@sorayafm
Copy link

sorayafm commented Feb 3, 2022

[root@serv-pru-apache etc]# echo "hola mundo lindo ahora son las: $(date)" | mailx -s "hola probando" soraya@correo.es

[root@serv-pru-apache etc]# Error in certificate: Peer's certificate issuer is not recognized.
smtp-server: 535 5.7.0 Invalid username or password
"/root/dead.letter" 11/365
. . . message not sent.

Can anyone help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment