使用google邮箱免费代发discourse邮件

论坛配置

注册google邮箱,配置app.yml或web_only.yml

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

stmp密码

stmp密码非邮箱密码,是google应用专用密码
安全性 (google.com)

image

测试脚本

import smtplib

# SMTP服务器设置
smtp_server = 'smtp.gmail.com'
smtp_port = 587
smtp_user = 'sobergou@gmail.com'
smtp_password = 'key_xxx' # key_xxx是google应用专用密码非邮箱密码

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

# 创建SMTP连接
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls()  # 启用TLS加密
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

注意事项

stmp密码非邮箱密码,是google应用专用密码