Linux uses mailx to send SMTP mail and related problems

» 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

 Linux uses mailx to send SMTP mail and related issues - geek Park

preface

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.

get ready

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 file etc/mail.rc

 #The user name authenticated by the SMTP server should be consistent with the user name and account below. There should be no Chinese set  from=info@mail.gitcafe.net #The address of the SMTP server set smtp= smtps://smtp.exmail.qq.com :465 #Ways of mail authentication set smtp-auth=login #The user name authenticated by the SMTP server set  smtp-auth-user=info@mail.gitcafe.net #User password (authorization code) authenticated by the SMTP server set smtp-auth-password=xxxxxoooooo #Ignore validation set ssl-verify=ignore #Here is the location of the certificate set 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"  sp91@qq.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 certificate mkdir -p /root/.certs/ echo -n | openssl s_ client -connect smtp.exmail.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 cd /root/.certs certutil -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.
Linux使用mailx发送SMTP邮件以及相关问题-极客公园

--Over--

-- 完 --

Comment

Your email address will not be disclosed. Required item used * tagging

2 replies to "Linux uses mailx to send SMTP mail and related issues"