»Toss and turn»Linux uses mailx to send SMTP mail and related problems
Using SMTP to send mail on the server side of Linux system
Today, I tried the database backup tool provided by LNMP, and found that it was OK. You can back up files and databases locally, and then send them to remote FTP. Well, that's what I want. You can uninstall the plug-in.
Then a friend in the group said that when the backup is successful, you can send an email to inform me, and then think that this thing should be possible.There is a mailx software on Linux. This tool can realize the function of sending mailbox, and then it was installed today. It records the process of use, and then some pits in the middle.
First of all, my operating system is centos7, and then the mailbox, using QQ enterprise 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 bring its own mailx. If not, it can be installed easily. This is a very small software, because my operating system here is CentOS, so all commands and commands here are in red hat system.Other systems can be replaced by themselves.
yum -y install mailx
Step 2 configure mail To configure a mailbox, you need to use SMTM. If you want to configure a mailbox, you need to use SMTM. There are many tutorials on the Internet. Today's focus is not on the mailbox side, but on sending mail on the server.
First of all, we don't have to think about port 25. Basically, we all use port 465.Therefore, we should use port 465 when setting, and then we can configure the parameters to set some values of SMTP just like others.The path is the fileetc/mail.rc
#The user name authenticated by the SMTP server should be consistent with the user name and account below. There should be no Chineseset email@example.com#The address of the SMTP serverset smtp=smtps://smtp.exmail.qq.com:465#Ways of mail authenticationset smtp-auth=login#The user name authenticated by the SMTP serverset firstname.lastname@example.org#User password (authorization code) authenticated by the SMTP serverset smtp-auth-password=xxxxxoooooo#Ignore validationset ssl-verify=ignore#Here is the 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 made clear. Then, the sender and the email account must be consistent. If this is not inconsistent, he cannot send.If this parameter is used, it is better to just change the email account and password, and do not change others.
echo "mail content" | mail -s "title" email@example.com
We try to send an e-mail and see if it can be sent to ourselves. Then I see that he can't send it. There are errors reported here, which are basically related to certificates. Therefore, we have to save a certificate locally, so we need to redo it.
Since I use QQ enterprise mailbox, all the commands are related to the limited origin of QQ. If it is any other mailbox, you can change it along with it, mainly to change his SMTP address.
#Here is the 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 see if you can send mail?This time should be able to send mail, anyway, Yunluo here is normal to receive mail.
-- 完 --
Published byClouds fall
No toss, no life, I am a rookie WordPress, a seller playing Taobao, welcome to know me, I am Yunluo!View all posts by cloud