261 lines
8.3 KiB
Python
261 lines
8.3 KiB
Python
import smtplib
|
||
from email.mime.text import MIMEText
|
||
from email.mime.multipart import MIMEMultipart
|
||
|
||
|
||
def test_smtp_detailed():
|
||
"""详细测试mail.sq0715.com的不同配置"""
|
||
server = 'mail.sq0715.com'
|
||
username = 'vip@sq0715.com'
|
||
password = 'Aalsq12350501.'
|
||
|
||
configs = [
|
||
{
|
||
'name': '587端口 + STARTTLS',
|
||
'port': 587,
|
||
'use_tls': True,
|
||
'use_ssl': False
|
||
},
|
||
{
|
||
'name': '465端口 + SSL',
|
||
'port': 465,
|
||
'use_tls': False,
|
||
'use_ssl': True
|
||
},
|
||
{
|
||
'name': '25端口 + STARTTLS',
|
||
'port': 25,
|
||
'use_tls': True,
|
||
'use_ssl': False
|
||
},
|
||
{
|
||
'name': '25端口 无加密',
|
||
'port': 25,
|
||
'use_tls': False,
|
||
'use_ssl': False
|
||
},
|
||
{
|
||
'name': '993端口 + SSL',
|
||
'port': 993,
|
||
'use_tls': False,
|
||
'use_ssl': True
|
||
}
|
||
]
|
||
|
||
for config in configs:
|
||
print(f"\n{'=' * 50}")
|
||
print(f"测试配置: {config['name']}")
|
||
print(f"服务器: {server}:{config['port']}")
|
||
print(f"TLS: {config['use_tls']}, SSL: {config['use_ssl']}")
|
||
print('=' * 50)
|
||
|
||
try:
|
||
# 创建SMTP连接
|
||
if config['use_ssl']:
|
||
print("使用SSL连接...")
|
||
smtp_server = smtplib.SMTP_SSL(server, config['port'], timeout=30)
|
||
else:
|
||
print("使用普通连接...")
|
||
smtp_server = smtplib.SMTP(server, config['port'], timeout=30)
|
||
|
||
# 开启调试模式
|
||
smtp_server.set_debuglevel(1)
|
||
|
||
print("连接建立成功,发送EHLO...")
|
||
smtp_server.ehlo()
|
||
|
||
# 如果需要STARTTLS
|
||
if config['use_tls']:
|
||
print("启动TLS加密...")
|
||
smtp_server.starttls()
|
||
smtp_server.ehlo() # 重新发送EHLO
|
||
|
||
print("尝试登录...")
|
||
smtp_server.login(username, password)
|
||
print("✅ 登录成功!")
|
||
|
||
# 发送测试邮件
|
||
print("发送测试邮件...")
|
||
msg = MIMEMultipart()
|
||
msg['From'] = username
|
||
msg['To'] = username # 发送给自己
|
||
msg['Subject'] = f'测试邮件 - {config["name"]}'
|
||
|
||
body = f"这是使用 {config['name']} 配置发送的测试邮件"
|
||
msg.attach(MIMEText(body, 'plain', 'utf-8'))
|
||
|
||
smtp_server.send_message(msg)
|
||
print("✅ 邮件发送成功!")
|
||
|
||
smtp_server.quit()
|
||
print(f"🎉 配置 '{config['name']}' 完全成功!")
|
||
|
||
return config # 返回成功的配置
|
||
|
||
except smtplib.SMTPAuthenticationError as e:
|
||
print(f"❌ 认证失败: {e}")
|
||
except smtplib.SMTPConnectError as e:
|
||
print(f"❌ 连接失败: {e}")
|
||
except smtplib.SMTPServerDisconnected as e:
|
||
print(f"❌ 服务器断开连接: {e}")
|
||
except smtplib.SMTPRecipientsRefused as e:
|
||
print(f"❌ 收件人被拒绝: {e}")
|
||
except Exception as e:
|
||
print(f"❌ 其他错误: {type(e).__name__}: {e}")
|
||
|
||
return None
|
||
|
||
|
||
if __name__ == '__main__':
|
||
print("开始测试 mail.sq0715.com 的SMTP配置...")
|
||
successful_config = test_smtp_detailed()
|
||
|
||
if successful_config:
|
||
print(f"\n🎉 找到可用配置!")
|
||
print("请在config.py中使用以下配置:")
|
||
print("-" * 40)
|
||
print(f"MAIL_SERVER = 'mail.sq0715.com'")
|
||
print(f"MAIL_PORT = {successful_config['port']}")
|
||
print(f"MAIL_USE_TLS = {successful_config['use_tls']}")
|
||
print(f"MAIL_USE_SSL = {successful_config['use_ssl']}")
|
||
print(f"MAIL_USERNAME = 'vip@sq0715.com'")
|
||
print(f"MAIL_PASSWORD = 'Aalsq12350501.'")
|
||
print(f"MAIL_DEFAULT_SENDER = 'vip@sq0715.com'")
|
||
else:
|
||
print("\n❌ 所有配置都失败了")
|
||
print("可能的原因:")
|
||
print("1. 邮箱密码不正确")
|
||
print("2. 邮箱服务器不支持SMTP")
|
||
print("3. 需要在邮箱设置中开启SMTP服务")
|
||
print("4. 服务器防火墙阻止了连接")
|
||
import smtplib
|
||
from email.mime.text import MIMEText
|
||
from email.mime.multipart import MIMEMultipart
|
||
|
||
|
||
def test_smtp_detailed():
|
||
"""详细测试mail.sq0715.com的不同配置"""
|
||
server = 'mail.sq0715.com'
|
||
username = 'vip@sq0715.com'
|
||
password = 'Aalsq12350501.'
|
||
|
||
configs = [
|
||
{
|
||
'name': '587端口 + STARTTLS',
|
||
'port': 587,
|
||
'use_tls': True,
|
||
'use_ssl': False
|
||
},
|
||
{
|
||
'name': '465端口 + SSL',
|
||
'port': 465,
|
||
'use_tls': False,
|
||
'use_ssl': True
|
||
},
|
||
{
|
||
'name': '25端口 + STARTTLS',
|
||
'port': 25,
|
||
'use_tls': True,
|
||
'use_ssl': False
|
||
},
|
||
{
|
||
'name': '25端口 无加密',
|
||
'port': 25,
|
||
'use_tls': False,
|
||
'use_ssl': False
|
||
},
|
||
{
|
||
'name': '993端口 + SSL',
|
||
'port': 993,
|
||
'use_tls': False,
|
||
'use_ssl': True
|
||
}
|
||
]
|
||
|
||
for config in configs:
|
||
print(f"\n{'=' * 50}")
|
||
print(f"测试配置: {config['name']}")
|
||
print(f"服务器: {server}:{config['port']}")
|
||
print(f"TLS: {config['use_tls']}, SSL: {config['use_ssl']}")
|
||
print('=' * 50)
|
||
|
||
try:
|
||
# 创建SMTP连接
|
||
if config['use_ssl']:
|
||
print("使用SSL连接...")
|
||
smtp_server = smtplib.SMTP_SSL(server, config['port'], timeout=30)
|
||
else:
|
||
print("使用普通连接...")
|
||
smtp_server = smtplib.SMTP(server, config['port'], timeout=30)
|
||
|
||
# 开启调试模式
|
||
smtp_server.set_debuglevel(1)
|
||
|
||
print("连接建立成功,发送EHLO...")
|
||
smtp_server.ehlo()
|
||
|
||
# 如果需要STARTTLS
|
||
if config['use_tls']:
|
||
print("启动TLS加密...")
|
||
smtp_server.starttls()
|
||
smtp_server.ehlo() # 重新发送EHLO
|
||
|
||
print("尝试登录...")
|
||
smtp_server.login(username, password)
|
||
print("✅ 登录成功!")
|
||
|
||
# 发送测试邮件
|
||
print("发送测试邮件...")
|
||
msg = MIMEMultipart()
|
||
msg['From'] = username
|
||
msg['To'] = username # 发送给自己
|
||
msg['Subject'] = f'测试邮件 - {config["name"]}'
|
||
|
||
body = f"这是使用 {config['name']} 配置发送的测试邮件"
|
||
msg.attach(MIMEText(body, 'plain', 'utf-8'))
|
||
|
||
smtp_server.send_message(msg)
|
||
print("✅ 邮件发送成功!")
|
||
|
||
smtp_server.quit()
|
||
print(f"🎉 配置 '{config['name']}' 完全成功!")
|
||
|
||
return config # 返回成功的配置
|
||
|
||
except smtplib.SMTPAuthenticationError as e:
|
||
print(f"❌ 认证失败: {e}")
|
||
except smtplib.SMTPConnectError as e:
|
||
print(f"❌ 连接失败: {e}")
|
||
except smtplib.SMTPServerDisconnected as e:
|
||
print(f"❌ 服务器断开连接: {e}")
|
||
except smtplib.SMTPRecipientsRefused as e:
|
||
print(f"❌ 收件人被拒绝: {e}")
|
||
except Exception as e:
|
||
print(f"❌ 其他错误: {type(e).__name__}: {e}")
|
||
|
||
return None
|
||
|
||
|
||
if __name__ == '__main__':
|
||
print("开始测试 mail.sq0715.com 的SMTP配置...")
|
||
successful_config = test_smtp_detailed()
|
||
|
||
if successful_config:
|
||
print(f"\n🎉 找到可用配置!")
|
||
print("请在config.py中使用以下配置:")
|
||
print("-" * 40)
|
||
print(f"MAIL_SERVER = 'mail.sq0715.com'")
|
||
print(f"MAIL_PORT = {successful_config['port']}")
|
||
print(f"MAIL_USE_TLS = {successful_config['use_tls']}")
|
||
print(f"MAIL_USE_SSL = {successful_config['use_ssl']}")
|
||
print(f"MAIL_USERNAME = 'vip@sq0715.com'")
|
||
print(f"MAIL_PASSWORD = 'Aalsq12350501.'")
|
||
print(f"MAIL_DEFAULT_SENDER = 'vip@sq0715.com'")
|
||
else:
|
||
print("\n❌ 所有配置都失败了")
|
||
print("可能的原因:")
|
||
print("1. 邮箱密码不正确")
|
||
print("2. 邮箱服务器不支持SMTP")
|
||
print("3. 需要在邮箱设置中开启SMTP服务")
|
||
print("4. 服务器防火墙阻止了连接")
|