環境:
雲伺服器(營運商不明) docker python3.6
25端口已打開
報錯的代碼
from flask import Flask
from flask_mail import Mail
from flask_mail import Message
app = Flask(__name__)
app.config['MAIL_SERVER'] = 'smtp.qq.com'
app.config['MAIL_PORT'] = 25
app.config['MAIL_USE_TLS'] = True
# 這個已被我修改,應該是你自己的qq号
app.config['MAIL_USERNAME'] = '[email protected]'
# 這個是你的授權碼,不是密碼
app.config['MAIL_PASSWORD'] = 'password'
mail = Mail(app)
def sendmail():
msg = Message("Hello",
sender="[email protected]",
recipients=["[email protected]"])
msg.body = "testing"
msg.html = "<b>testing</b>"
mail.send(msg)
with app.app_context():
sendmail()
修改後的代碼
from flask import Flask
from flask_mail import Mail
from flask_mail import Message
app = Flask(__name__)
app.config['MAIL_SERVER'] = 'smtp.qq.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = '93737[email protected]'
app.config['MAIL_PASSWORD'] = 'rdyuwlebtveybfae'
mail = Mail(app)
def sendmail():
msg = Message("Hello",
sender="[email protected]",
recipients=["[email protected]"])
msg.body = "testing"
msg.html = "<b>testing</b>"
mail.send(msg)
with app.app_context():
sendmail()
可見以上隻改了端口,從25改到587就沒問題了
是以可以初步推斷是25端口被營運商封了,自己打開也等于沒打開,換個端口就好了