Nim std/smtp连接web.de发邮件报503 Bad sequence of commands错误
Nim
std/smtp 连接web.de邮箱发送邮件失败问题 问题背景
我使用Nim编程语言开发Web应用,近期计划实现邮件发送相关功能。Nim官方提供的std/smtp标准库附带了starttls和ssl两种连接方式的简易使用示例,我在本地邮件服务商web.de注册了测试邮箱用于功能调试,尽可能严格参考示例编写代码后始终无法正常运行。
测试代码
import std/[smtp] let smtpServerName = "smtp.web.de" let startTlsportNumber = 587 let un = "dummymail" # 替换为实际用户名 let pw = "dummypw" # 替换为实际密码 let target = "bla@mailinator.com" # StartTLS 代码块:两种模式二选一启用,不要同时生效 let smtpConn = newSmtp(debug=true) smtpConn.connect(smtpServerName, Port startTlsportNumber) smtpConn.startTls() # SSL 代码块:两种模式二选一启用,不要同时生效 # let sslPortNumber = 465 # let smtpConn = newSmtp(useSsl = true, debug=true) # smtpConn.connect(smtpServerName, Port sslPortNumber) var msg = createMessage(mSubject = "Hello from Nim's SMTP", mBody = "Hello!.\n Is this awesome or what?", mTo = @[target]) smtpConn.auth(un, pw) smtpConn.sendmail(un, @[target], $msg)
报错现象
我分别测试了两种连接模式,均触发运行时错误:
- 587端口startTLS模式:调用
smtpConn.startTls方法时,服务器返回503响应,调试日志如下:
S:220 web.de (mrweb105) Nemesis ESMTP Service ready C:HELO smtp.web.de S:250 web.de Hello smtp.web.de [46.183.103.17] C:STARTTLS S:503 Bad sequence of commands C:QUIT /home/philipp/dev/playground/src/playground.nim(11) playground /usr/lib/nim/pure/smtp.nim(246) startTls /usr/lib/nim/pure/smtp.nim(226) checkReply /usr/lib/nim/pure/smtp.nim(110) quitExcpt Error: unhandled exception: Expected 220 reply, got: 503 Bad sequence of commands [ReplyError]
- 465端口SSL模式:调用
smtpConn.connect方法时就收到服务器返回的503响应,调试日志如下:
S:220 web.de (mrweb005) Nemesis ESMTP Service ready C:HELO smtp.web.de S:503 Bad sequence of commands C:QUIT /home/philipp/dev/playground/src/playground.nim(15) playground /usr/lib/nim/pure/smtp.nim(240) connect /usr/lib/nim/pure/smtp.nim(231) helo /usr/lib/nim/pure/smtp.nim(226) checkReply /usr/lib/nim/pure/smtp.nim(110) quitExcpt Error: unhandled exception: Expected 250 reply, got: 503 Bad sequence of commands [ReplyError]
已排查内容
- 端口配置核对无误:服务商明确说明587为startTls端口、465为SSL端口
- 编译参数无问题:在Arch Linux环境下编译时均添加了
-d:ssl参数,排除SSL相关编译参数缺失问题 - 同一份代码连接Gmail邮箱可正常发送邮件,仅连接web.de时始终失败
- 检索相关错误信息提示该问题可能与认证有关,但按照SMTP协议流程,认证应在startTls建立加密连接之后执行,未排查出
std/smtp库的使用错误,咨询该问题的根因与解决方案。
内容的提问来源于stack exchange,提问作者Philipp Doerner
相关产品推荐
相关产品推荐

