The Linux servers used on many VPSs have streamlined the mail sending component, resulting in the server not being able to send out notification emails, and some functions (such as retrieving passwords, confirming registrations, and so on) that require emails to be sent will be affected. WordPress has many SMTP plugins that can help us send emails via STMP, simply set the SMTP information in the background.
If there are many WordPress sites hosted on one server, it will be very tedious to operate. Today we introduce a program that can send emails using SMTP directly on Linux: Mailx, this program can help us to make the server directly support email sending, no need to set up on each site.
Installing the Mailx program
Today, we will use Centos as an example. Installing Mailx on Centos is very simple, and can be done directly using yum. Before installing, it is recommended that you remove any 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
Configuring SMTP to Send Mail
General mail server will provide smtp, smtps and smtp starttls service to send mail. smtp is the simplest and the most insecure, it is not recommended to use, it is best to use smtps or smtp starttls to send mail. Let's use QQ mailbox as an example to show how to configure Mailx. mailx configuration file is /etc/mail.rc, edit this file, add the following configurations, choose one of the two ways.
[wprs_c-alert type="info" content="Note: The password of QQ mailbox is the "authorization code" generated inside the QQ mailbox account settings, not the QQ password or the QQ mailbox independent login password. password or QQ mailbox independent login password." /]
Configuring smtps for sending emails
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
Configuring starttls for sending emails
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 be able to receive test emails sent from the server.
echo "Hello" | mail -v -s "test" xxx@qq.com
Using the above configuration, the email is fully capable of being sent out, but when sending the email, it will prompt "Error in certificate: Peer's certificate issuer is not recognized. If you want to generate a certificate, just run the following command.
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 complete, modify the mail.rc mail configuration, change the nss-config-dir to /root/.certs generated by the above command, and save it.
Referring to the above settings, you can also use 126, 163 and other mailboxes on the server.Send mail via SMTPAfter you have set up the mailbox, all WordPress sites on your server, or sites developed in other programs or languages can send emails directly. After successful setup, all WordPress sites on the server, or sites developed in other programs or languages, can send emails directly, isn't it very convenient?
9 thoughts on “使用 Mailx 通过 SMTP 在 Centos 上发送邮件,解决 WordPress 发送邮件问题”
It's indeed much more convenient, no need to install plugins.
Executing these commands still results in the same error, "Error in certificate: Peer's certificate issuer is not recognized."
What's going on?
The order was executed as stated above:
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
The email was able to be sent, but there was still an error, the same error message "Error in certificate: Peer's certificate issuer is not recognized."
Try setting the sender of the email to be the same as the SMTP mailbox.
There's a missing entry in the certificate generation section, just add it.
After executing the four commands, cd to the /root/.certs/ directory.
then execute
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d . / -i qq.crt
I've been screwed by you for an hour because in your statement, the center dot before G3 is a Chinese character
The pot isn't @Mapleleaf's, the comment that was posted was correct, and for some reason, it was auto-transcoded by WordPress. I've edited this comment to add pre so that others don't get screwed.
Don't you have to set it up in wordpress? centos sends it fine with commands, but wordpress just doesn't work. Just enable the plugin.
You can look at the mailx logs to see if any errors are reported.