Using Mailx with SMTP on CentOS to Fix WordPress Email Delivery

The Linux servers used on many VPS have streamlined email sending components, resulting in no notification emails being sent on the server, and some functions that require emails (such as retrieving passwords, confirming registration, etc.) will be affected. WordPress has many SMTP plug-ins that can help us send emails through STMP. Simply set the SMTP information in the background.

If there are many WordPress sites hosted on one server, the operation will be very cumbersome. Today I will introduce to you a program that can directly use SMTP to send emails on Linux: Mailx. This program can help us make the server directly support email sending, without having to set it up on each site.

Install Mailx program

Today, we will take Centos as an example. Installing Mailx on Centos is very simple. You can install it directly using yum. Before installation, it is recommended to remove postfix or sendmail programs that are no longer needed and may cause conflicts.

yum -y remove postfix
yum -y remove sendmail

Install the Mailx program:

yum -y install mailx

Configure SMTP to send email

Generally, mail servers provide smtp, smtps and smtp starttls services to send mails. smtp is the simplest and most unsafe. It is not recommended to use. It is best to use smtps or smtp starttls to send emails. Let’s use QQ mailbox as an example to illustrate how to configure Mailx. The configuration file of Mailx is /etc/mail.rc. Edit this file and add the following configuration. Choose one of the two methods.

Note: The QQ mailbox password is the “authorization code” generated in the QQ mailbox account settings, not the QQ password or the QQ mailbox independent login password.

Configuration of sending emails via smtps

set nss-config-dir=/etc/pki/nssdb
set ssl-verify=ignore
set smtp=smtps://smtp.qq.com:465
set smtp-auth=login
set smtp-auth-user=xxx@qq.com
set smtp-auth-password=xxx
set from=xxx@qq.com

Starttls method to send email configuration

set smtp-use-starttls
set nss-config-dir=/etc/pki/nssdb
set ssl-verify=ignore
set smtp=smtp.qq.com:587
set smtp-auth=login
set smtp-auth-user=xxx@qq.com
set smtp-auth-password=xxx
set from=xxx@qq.com

After adding the above configuration and saving it, run the following command to test sending emails. If there are no accidents, our mailbox will soon receive the test emails sent from the server.

echo "Hello" | mail -v -s "test" xxx@qq.com

Using the above configuration, the email can be sent out completely, but when sending the email, it will prompt “Error in certificate: Peer’s certificate issuer is not recognized.”. Just run the following command to generate a certificate.

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

After the generation is completed, modify the mail.rc mail configuration, modify nss-config-dir to /root/.certs generated by the above command, and save it.

Referring to the above settings, you can also use mailboxes such as 126 and 163 on the server.Send mail via SMTP. After the setting is successful, all WordPress sites on the server, or sites developed by other programs or other languages, can send emails directly. Isn’t it very convenient?

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *