Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request - 添加 Message-ID 以修复 Gmail 拒收问题
错误描述
我们在发送电子邮件到 Gmail 时遇到了邮件拒收的问题。Gmail 服务器返回的错误信息如下:
这表明我们的邮件因为缺少有效的
Message-ID
标头而被 Gmail 拒绝接收。根据 RFC 5322 规范,Message-ID
是电子邮件标准协议的一部分,每封邮件都需要一个唯一的Message-ID
。解决方案
为了解决这个问题,我在邮件发送功能中添加了生成和包含
Message-ID
的逻辑。Message-ID
是根据发件人的电子邮件地址动态生成的,确保了每封邮件都具有唯一的标识符。修改后的代码主要在
SendEmail
函数中进行了以下更改:SMTPFrom
中提取域名部分。crypto/rand
包生成一串随机字符。Message-ID
。Message-ID
。通过这些更改,我们的邮件现在包含了符合 RFC 5322 规范的有效
Message-ID
,成功解决了 Gmail 拒收的问题。请审阅这些更改,并考虑合并到主分支。如果有任何问题或需要进一步的讨论,请随时与我联系。