Sending Emails with Mailx

How to send E-Mail on liunx.

CentOS 7

$ sudo yum update -y
$ sudo yum install mailx -y
$ sudo mail -V
$ sudo vim /etc/mail.rc
set from=sayboy@163.com
set smtp=smtps://smtp.163.com:465
set smtp-auth-user=sayboy@163.com
set smtp-auth-password=password
set ssl-verify=ignore
set nss-config-dir=~/.certs/

Generate the certificate

$ mkdir ./.certs
$ echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.mail.crt
$ certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/opt/163.mail.crt
$ certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/opt/163.mail.crt

Verify the certificate

$ cd ~/.certs && ll
$ certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.mail.crt

$ certutil -L -d /root/.certs

Sending

$ echo "Hello world" | mail -s "Test mail" daodaotest@163.com
$ echo "Hello world" | mail -v -c "user2@163.com,user3@qq.com" -s "Test mail" -a files.zip user1@163.com
Licensed under CC BY-NC-SA 4.0
comments powered by Disqus