程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Failure reason of sending email using Python in VMware virtual machine Linux system

編輯:Python

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 :

One 、 There are two reasons for python Send an email with an error (java The same applies )

  • reason 1:25 Port closure ; resolvent : Use 465 Port send ;
  • reason 2:hostname Hostname has no mapping ; resolvent : stay /etc/hosts Mapping .

Two 、25 The solution of port closure

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 .")

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved