Skip to content

Instantly share code, notes, and snippets.

@ilkereroglu
Created September 22, 2015 21:53
Show Gist options
  • Star 36 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • 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
@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