Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 发送邮件时添加 Message-ID #732

Merged
merged 2 commits into from
Nov 24, 2023

Conversation

ShinChven
Copy link
Contributor

Pull Request - 添加 Message-ID 以修复 Gmail 拒收问题

错误描述

我们在发送电子邮件到 Gmail 时遇到了邮件拒收的问题。Gmail 服务器返回的错误信息如下:

host gmail-smtp-in.l.google.com[] said: 550-5.7.1 [] Messages missing a valid Message-ID header are not accepted. Please visit https://support.google.com/mail/?p=RfcMessageNonCompliant and review RFC 5322 specifications for more information.

这表明我们的邮件因为缺少有效的 Message-ID 标头而被 Gmail 拒绝接收。根据 RFC 5322 规范,Message-ID 是电子邮件标准协议的一部分,每封邮件都需要一个唯一的 Message-ID

解决方案

为了解决这个问题,我在邮件发送功能中添加了生成和包含 Message-ID 的逻辑。Message-ID 是根据发件人的电子邮件地址动态生成的,确保了每封邮件都具有唯一的标识符。

修改后的代码主要在 SendEmail 函数中进行了以下更改:

  1. SMTPFrom 中提取域名部分。
  2. 使用 crypto/rand 包生成一串随机字符。
  3. 将这些字符和域名组合成一个唯一的 Message-ID
  4. 在邮件头信息中添加这个 Message-ID

通过这些更改,我们的邮件现在包含了符合 RFC 5322 规范的有效 Message-ID,成功解决了 Gmail 拒收的问题。


请审阅这些更改,并考虑合并到主分支。如果有任何问题或需要进一步的讨论,请随时与我联系。

ShinChven and others added 2 commits November 20, 2023 21:34
- Extract domain from SMTPFrom
- Generate a unique Message-ID
- Add Message-ID to email headers
@songquanpeng songquanpeng merged commit b4d67ca into songquanpeng:main Nov 24, 2023
@songquanpeng
Copy link
Owner

Thx~

dirname pushed a commit to dirname/one-api that referenced this pull request Nov 24, 2023
* feat: Add Message-ID to email headers to comply with RFC 5322

- Extract domain from SMTPFrom
- Generate a unique Message-ID
- Add Message-ID to email headers

* chore: check slice length

---------

Co-authored-by: JustSong <[email protected]>
dirname pushed a commit to dirname/one-api that referenced this pull request Nov 24, 2023
feat: support cloudflare gateway for azure (songquanpeng#666)

* 🐛 Fix cloudflare gateway request failure

* 🐛 fix channel test url error

fix: skip JSON deserialization when accessing transcriptions and translations (songquanpeng#718)

* fix: Skip JSON deserialization when accessing transcriptions and translations.

* chore: update impl

---------

docs: update readme (songquanpeng#724)

feat: update request struct (close songquanpeng#708)

refactor: remove consumeQuota  related logic (songquanpeng#738)

* feat: 删除relay-text中的consumeQuota变量

该变量始终为true,可以删除

* chore: remove useless code

---------

fix: add Message-ID header for email  (songquanpeng#732)

* feat: Add Message-ID to email headers to comply with RFC 5322

- Extract domain from SMTPFrom
- Generate a unique Message-ID
- Add Message-ID to email headers

* chore: check slice length

---------

fix: add Date header for email (songquanpeng#742)

* 修复自建邮箱发送错误: INVALID HEADER Missing required header field: "Date"

* chore: fix style

---------

feat: support Azure's Whisper model (songquanpeng#720)

docs: add pr template

docs: update readme
Co-Authored-By: JustSong <[email protected]>
Co-Authored-By: liyujie <[email protected]>
Co-Authored-By: JustSong <[email protected]>
dirname pushed a commit to dirname/one-api that referenced this pull request Nov 24, 2023
* feat: Add Message-ID to email headers to comply with RFC 5322

- Extract domain from SMTPFrom
- Generate a unique Message-ID
- Add Message-ID to email headers

* chore: check slice length

---------

Co-authored-by: JustSong <[email protected]>
greeeds pushed a commit to greeeds/one-api that referenced this pull request Mar 3, 2024
* feat: Add Message-ID to email headers to comply with RFC 5322

- Extract domain from SMTPFrom
- Generate a unique Message-ID
- Add Message-ID to email headers

* chore: check slice length

---------

Co-authored-by: JustSong <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants