My method referenced many tutorials, fixed the errors and worked successfully.
Install mailutils
1
sudo apt install mailutils
Configure username and password
1
sudo nano /etc/postfix/sasl_passwd
Input SMTP server, account and password.
1
[smtp.126.com]:465 username@126.com:password
The password of the 126 mailbox needs to generate an authorization code in the settings. Then run postmap.
1
sudo postmap /etc/postfix/sasl_passwd
Map sender
By default, postfix uses your username@hostname (the one you can see in the title bar of the Ubuntu Console window) to send emails. Such emails will be rejected by the smtp server (553 Mail from must equal authorized user), so you need to put it mapped to your real email address.
1
sudo nano /etc/postfix/generic
Write mapping.
1
root@ubuntu username@126.com
Then run postmap.
1
sudo postmap /etc/postfix/generic
Modify the configuration file
1
sudo nano /etc/postfix/main.cf
edit relayhost.
1
relayhost = [smtp.126.com]:465
Add the following configuration at the end of the file.
sudo service postfix restart echo"test" | mail -s "hello" target@126.com
View running log
If there is no response after running, see if there is any error in the log, so as to search and solve the problem in a targeted manner. You can open a separate terminal and place it next to it to view the log in real time.