»Technical toss»Linux uses mailx to send SMTP mail and related problems
Linux system uses SMTP to send mail on the server side
preface
Today, I tried the database backup tool provided by LNMP, and found that it is OK. You can back up files and databases locally, and then send them to the remote ftp. Hmm, that's what I want. You can uninstall the plug-in.
Then a friend in the group said that when the backup was successful, he could send an email to notify them, and then think about how this could be achieved.Search for a Mailx software tool on Linux to implement the function of sending mailboxes, and then install it today, which records the process of use, and some pitfalls in the middle.
get ready
First of all, my operating system is centos7, and the mailbox is QQ corporate mailbox.
#SMTP protocol Sending mail server: smtp.exmail.qq.com, using SSL, port number 465 #Overseas users can use the following servers Sending mail server: hwsmtp.exmail.qq.com, using SSL, port number 465
The first step is to use mailx. First of all, if the system is normal, it should have its own mailx. If not, it can be easily installed. This is a very small software. Because my operating system is Centos, all commands here use the Red Hat system.Other systems can be replaced by themselves.
yum -y install mailx
Step 2: Configure Mail If you need to configure the mailbox on the mail side and the server side and then the fuel tank side, it is unnecessary to say that you must use the smtm. There are many online tutorials set up by yourself. Today's focus is not on the mailbox side, but on sending mail on the server.
First of all, we don't need to think about port 25. It's basically impossible. So we basically use port 465.So when setting, we should first use port 465, and then we should configure it. The parameters are the same as others, and we will set some SMTP values.The path is this fileetc/mail.rc
#The user name authenticated by the smtp server should be consistent with the following user name and account, not in Chineseset from=info@mail.gitcafe.net#Address of smtp serverset smtp=smtps://smtp.exmail.qq.com:465#Email authentication modeset smtp-auth=login#User name authenticated by smtp serverset smtp-auth-user=info@mail.gitcafe.net#User password (authorization code) authenticated by smtp serverset smtp-auth-password=xxxxxoooooo#Ignore validationset ssl-verify=ignore#The following is the storage location of the certificateset nss-config-dir=/root/.certs/
There are two of them. The first one is his. This password is the authorization code, not the login password of Youjiang's mailbox. This must be clear. The second one is that the sender must be consistent with the mailbox account. If he is not inconsistent, he cannot send.For this parameter, it is better to just change the email account and password.
echo "mail content" | mail -s "title" sp91@qq.com
We tried to send an email to ourselves. Then I checked that he could not send it. There was an error. The error here was basically related to the certificate, so we had to save a certificate locally, so we had to redo it.
Because I use QQ mailbox, all commands are related to the limited origin of QQ. If it is other mailboxes, you can change the address of his smtp.
#The following is the storage location of the certificatemkdir -p /root/.certs/echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crtcertutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crtcertutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crtcertutil -L -d /root/.certscd /root/.certscertutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
After executing this command, try again to test whether you can send mail?It should be possible to send emails this time. Anyway, Yunluo receives emails normally here.