pycontw / pycon.tw

PyCon TW Proposal System & Backend Server
https://tw.pycon.org/prs
MIT License
95 stars 107 forks source link

寄信功能確認(e.g. 忘記密碼) #1102

Open josix opened 2 years ago

josix commented 2 years ago

要替換 dev@pycon.tw https://discord.com/channels/752904426057892052/958314910046117909/974424221277118484

iknowright commented 10 months ago

要換 dev@pycon.tw 至別的信箱可以

可以使用 Google STMP Relay + Postfix (MTA/SMTP) 達成。

實驗結果:

  1. 先架設一個 Postfix server 在 local, 使用專案 dockerized postfixdocker run --rm --name postfix -e "ALLOWED_SENDER_DOMAINS=gmail.com" -e "RELAYHOST=smtp-relay.gmail.com:25" -p 1587:587 boky/postfix
  2. 使用 python 發起 email, 因爲是 relay 其實不用任何 auth, 讓 google smtp relay 那邊處理
    import smtplib
    with smtplib.SMTP("127.0.0.1", 1587) as server:
    server.sendmail("changchaishi@gmail.com", "changchaishi@gmail.com", "test email")
  3. local postfix 會嘗試聯係 google smtp 做寄信,以下 log
    2024-01-27T15:20:17.261938+00:00 INFO    postfix/smtp[495]: connect to smtp-relay.gmail.com[2404:6800:4008:c07::1c]:25: Cannot assign requested address
    2024-01-27T15:20:19.152881+00:00 INFO    postfix/smtp[495]: 0A9ED1FB521: to=<changchaishi@gmail.com>, relay=smtp-relay.gmail.com[64.233.189.28]:25, delay=2.1, delays=0.05/0.02/1.9/0.16, dsn=5.7.0, status=bounced (host smtp-relay.gmail.com[64.233.189.28] said: 550-5.7.0 Mail relay denied [111.71.216.3]. Invalid credentials for relay for 550-5.7.0 one of the domains in:  (as obtained from HELO and MAIL FROM). 550-5.7.0  Email is being sent from a domain or IP address which isn't 550-5.7.0 registered in your Workspace account. Please login to your Workspace 550-5.7.0 account and verify that your sending device IP address has been 550-5.7.0 registered within the Workspace SMTP Relay Settings. For more 550-5.7.0 information, go to 550 5.7.0  https://support.google.com/a/answer/6140680#maildenied n1-20020a634001000000b005ce06f2a3d3sm162744pga.17 - gsmtp (in reply to MAIL FROM command))
    2024-01-27T15:20:19.154488+00:00 INFO    postfix/cleanup[494]: 25A0F1FB525: message-id=<20240127152019.25A0F1FB525@eaf077279093>
    2024-01-27T15:20:19.159657+00:00 INFO    postfix/qmgr[437]: 25A0F1FB525: from=<>, size=3404, nrcpt=1 (queue active)
    2024-01-27T15:20:19.159696+00:00 INFO    postfix/bounce[496]: 0A9ED1FB521: sender non-delivery notification: 25A0F1FB525
    2024-01-27T15:20:19.159886+00:00 INFO    postfix/qmgr[437]: 0A9ED1FB521: removed

這個 log 結果是預期的。剩下的就是看有沒有 google workspace owner (pycon.tw domain)可以一起拉實際實驗上去