使用阿里云邮箱免费代发discourse邮件

论坛配置

注册阿里云邮箱,配置app.yml或web_only.yml
key_xxx为邮箱密码,测试ssl,discourse不支持ssl,使用80端口,关闭默认tls使能

  DISCOURSE_SMTP_ADDRESS: smtp.aliyun.com
  DISCOURSE_SMTP_PORT: 80
  DISCOURSE_SMTP_USER_NAME: sobergou@aliyun.com
  DISCOURSE_SMTP_PASSWORD: "key_xxx"
  DISCOURSE_SMTP_ENABLE_START_TLS: false           # (optional, default true)
  DISCOURSE_SMTP_DOMAIN: aliyun.com
  DISCOURSE_NOTIFICATION_EMAIL: sobergou@aliyun.com

测试脚本

import smtplib, ssl

# SMTP服务器设置
smtp_server = 'smtp.aliyun.com'
smtp_port = 465
smtp_user = 'sobergou@aliyun.com'
smtp_password = 'key_xxx' # key_xxx为邮箱密码,测试ssl,discourse不支持ssl,使用80端口,关闭默认tls使能

# 邮件内容
from_addr = 'sobergou@aliyun.com'
to_addr = 'sobergou@aliyun.com'
subject = 'SMTP Test Email'
body = 'This is a test email sent via SMTP.'

# 创建SMTP连接
ctxt = ssl.create_default_context()
ctxt.set_ciphers('DEFAULT')
server = smtplib.SMTP_SSL(smtp_server, smtp_port, context=ctxt)
server.login(smtp_user, smtp_password)

# 发送邮件
msg = f"From: {from_addr}\r\nTo: {to_addr}\r\nSubject: {subject}\r\n\r\n{body}"
server.sendmail(from_addr, to_addr, msg)
server.quit()

print("Test email sent successfully!")

测试结果

自己给自己发份邮件
image