Alibaba Cloud CentOS7 server builds a mail server, port: 465

I set up a mail server on Alibaba Cloud before and opened port 25 in the cloud backend, but I couldn't send emails. I finally asked the ticket and realized that I stepped on the pit again.
Insert picture description here
Solution: You need to use the cloud server on Alibaba Cloud to send emails to the outside. You can use Alibaba Cloud Mail products or use the 465 port provided by a third-party mail service provider. Here I choose to configure port 465 to send emails, the specific steps are as follows:

1. Install mail service
yum -y install mailx

2. Open the third-party authorization code in the mailbox
. It depends on the kind of mailbox that the individual uses. I use the 163 mailbox here. The steps to open the third-party authorization code are not written here.

3. Modify the configuration
vim /etc/mail.rc and
add the following lines at the end of the mail.rc file to configure
set from=xxxxxx # Fill in the sender's mailbox here
set smtp=smtps://smtp.163.com:465
#set smtp=smtps://smtp.qq.com:465 # qq mailbox uses this, it is recommended to use qq mailbox as the sender, sometimes the 163 mailbox is quite bad, and the email is rejected
set ssl-verify=ignore # set ssl Ignore verification (certificate warning)
set nss-config-dir=/root/.certs # Define the directory where the certificate is located
set [email protected] #Mailbox username
set smtp-auth-password=xxxxxxx #fill here Email authorization code (after trying to fill in the password is invalid, must fill in the authorization code)
set smtp-auth=login #Set the authentication method

4. Create a certificate directory
mkdir /root/.certs

5.ssl authorization
cd /root/.certs #Get the
mail server certificate
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne'/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt


#Add the certificate to the trusted list certutil -A -n "GeoTrust SSL CA" -t "C," -d ~/.certs -i ~/.certs/163.crt
certutil -A -n "GeoTrust Global CA" -t "C," -d ~/.certs -i ~/.certs/163.crt
certutil -A -n "GeoTrust SSL CA-G3" -t "Pu,Pu,Pu" -d ~/.certs/ ./ -i 163.crt

In the above command, -A means add, -n means nickname, which can be taken at will, such as 126 or qq; -t means trusted label, the possible values ​​are t/c/p or their combination; -d means the certificate is located Directory, -i indicates the location of the certificate file.


#Query certificate certutil -L -d /root/.certs


#Adjust the permissions of the certificate directory chmod 777 * /root/.certs

[root@test1 15:36:30 ~/.certs]#ll
total 100
-rwxrwxrwx 1 root root  2415 Dec 26 15:51 163.crt
-rwxrwxrwx 1 root root 65536 Dec 26 15:53 cert8.db
-rwxrwxrwx 1 root root 16384 Dec 26 15:53 key3.db
-rwxrwxrwx 1 root root 16384 Dec 26 15:51 secmod.db

The mail server is now complete!

6. The mail server is set up, and of course it is necessary to test it.
Let’s first understand some common commands of mail
a. No mail body

mail -s "mail subject" recipient address (receiving mailbox)

b. There is a message body

Form 1:
mail -s "mail subject" recipient address <file (or mail body.txt)
Form 2:
echo "mail body" | mail -s "mail subject" recipient address
Form 3:
cat mail body.txt | mail -s "mail subject" recipient address

c. Mail with attachments

mail -s "mail subject" recipient address -a attachment <file (mail body.txt)

Test sending mail:
echo "test.text" | mail -s "Mail server test" xxxxxx.qq.com

received e-mail:
Insert picture description here

testing successfully!

Guess you like

Origin blog.csdn.net/weixin_44901564/article/details/111914395
Recommended