Groping for a long time , Most of the Internet is about 25 Processing method of port closure , Another method is not easy to find , Not easy to detect , This situation is often manifested in , You can successfully send mail on Alibaba cloud server , And here it is vmware linux Cannot send in virtual machine , The treatment is as follows :
Use 465 Port to send mail ,python The source code of the implementation is as follows :
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName :smtp.py
# @Time :2020/11/25 13:21
# @Author :Oscar
import smtplib
from smtplib import SMTPException
from email.header import Header
from email.mime.text import MIMEText
mail_host = 'smtp.163.com'
mail_user = '[email protected]'
mail_pass = 'xxx'
mail_port = 465
# Send E-mail
def send_email(subject, content, to):
# noinspection PyBroadException
try:
print(" Send a notification email .")