Repository navigation
feat: 连接代理(HTTP CONNECT / SOCKS)for IMAP and SMTP - #32
Open
sujianddd-dev wants to merge 1 commit into
Open
sujianddd-dev wants to merge 1 commit into
sujianddd-dev wants to merge 1 commit into
Conversation
网络经代理才能连邮箱服务器时(例如 Gmail 在部分网络下直连不通),插件此前只能直连: nodemailer 没有代理选项,插件也没有把代理传给 imapflow。 - 账号新增 `proxy`(`http` CONNECT / `https` / `socks4` / `socks4a` / `socks5` / `socks5h`, 省略协议按 http 处理),账号级覆盖顶层简写,具名账号可各自不同。 - 未配置时按 `HTTPS_PROXY` → `HTTP_PROXY` → `ALL_PROXY` 回退,并遵守 `NO_PROXY`; 显式配置优先于 `NO_PROXY`,因为那是用户对这个账号的直接意图。 - IMAP 交给 imapflow 自带的 `proxy` 选项;SMTP 在插件已有的 `getSocket` 钩子里 建立 CONNECT / SOCKS 隧道,再由 nodemailer 在隧道上起 TLS,`servername` 固定为真实 邮箱主机,证书校验不会落到代理上。 - 代理地址在配置解析阶段校验,写错会在「设置 → 邮件」报错,而不是使用时报一个 连接超时。直连路径与之前完全一致(不传 proxy 时不新增任何选项)。 - POP3 收信暂不支持代理,文档已注明。 - 测试:test/proxy.test.mjs 覆盖地址解析、环境回退与 NO_PROXY、CONNECT 隧道、 代理拒绝(407)与不可达报错、配置继承与校验;全套 413 项通过。 Add connection proxies for IMAP and SMTP: account-level `proxy` (http CONNECT / https / socks4 / socks4a / socks5 / socks5h) with HTTPS_PROXY / HTTP_PROXY / ALL_PROXY and NO_PROXY fallback. IMAP uses imapflow's proxy option; SMTP tunnels inside the existing getSocket hook and leaves TLS to nodemailer with servername pinned to the real mail host, so certificates keep validating the mail server rather than the proxy. POP3 is documented as not yet covered.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
问题
插件只能直连邮箱服务器:
nodemailer本身没有代理选项,插件也没有把代理传给imapflow(它其实自带proxy选项)。在网络必须经代理才能连 Gmail/Outlook 的环境里(例如国内直连 smtp.gmail.com:465、imap.gmail.com:993 不通),email_send表现为 60 秒工具超时或ESOCKET connect ETIMEDOUT,只能靠外部中继脚本绕过。改动
proxy:http(CONNECT) /https/socks4/socks4a/socks5/socks5h;省略协议按http处理(127.0.0.1:7897这种粘贴写法直接可用)。账号级覆盖顶层简写,具名账号可各自不同。HTTPS_PROXY→HTTP_PROXY→ALL_PROXY(大小写皆可),并遵守NO_PROXY。显式配置的proxy优先于NO_PROXY:那是用户对这个账号的直接意图。getSocket钩子里建立 CONNECT / SOCKS 隧道,再由 nodemailer 在隧道上起 TLS,servername固定为真实邮箱主机——证书校验落在邮箱服务器而不是代理上。src/config.ts),写错会在「设置 → 邮件」报代理地址无效,而不是使用时报一个说不清的超时。proxy时不新增任何传输选项。socks提升为显式依赖(原本只是 imapflow 的传递依赖,直接import必须声明)。docs/USAGE.md、docs/USAGE.en.md新增「代理」一节与配置项表格行;README 中英文各加一句;CHANGELOG 加「未发布」条目。验证
node --test "test/*.test.mjs":413 项全部通过(新增test/proxy.test.mjs6 项:地址解析、环境回退与NO_PROXY、CONNECT 隧道真实回显、代理 407 拒绝、代理不可达、配置继承与校验)。127.0.0.1:7897,Gmail 账号):new ImapFlow({..., proxy:'http://127.0.0.1:7897'})→ 连接成功,列出 9 个文件夹,\Sent为[Gmail]/已发邮件。openProxiedSocket('http://127.0.0.1:7897','smtp.gmail.com',465)交给 nodemailer 的getSocket+servername→transporter.verify()返回true,1.7 秒。说明与后续
cordis.patch.yml的proxy、账号卡片的 YAML 区(accountsYaml),或直接设环境变量HTTPS_PROXY。如果作者希望设置页也可编辑,我可以在这个 PR 里补上账号卡片的字段与三态序列化。node-pop3客户端自行建连),文档已写明;需要的话另开一个 PR。