在使用SMTPClient.jl
库通过curl_easy_perform()
函数发送电子邮件时,如果遇到“SSL对等证书或SSH远程密钥不正常”的错误,通常是由于以下几个原因造成的:
SMTPClient.jl
或底层libcurl
库可能未正确配置SSL选项。确保目标SMTP服务器的SSL证书是有效的,并且受信任。可以通过浏览器访问SMTP服务器的HTTPS地址来验证证书。
在某些情况下,系统可能缺少最新的CA证书包。可以尝试更新系统的CA证书包:
sudo update-ca-certificates
确保libcurl
使用系统的证书存储。可以在Julia代码中设置:
using SMTPClient
# 设置libcurl使用系统的证书存储
ENV["CURL_CA_BUNDLE"] = "/etc/ssl/certs/ca-certificates.crt"
# 发送邮件
smtp = SMTP("smtp.example.com"; port=587, auth=true, user="user", pass="password")
send(smtp, "from@example.com", "to@example.com", "Subject", "Hello, World!")
在调试时,可以临时禁用SSL验证,但不建议在生产环境中使用这种方法,因为它会使连接不安全。
using SMTPClient
smtp = SMTP("smtp.example.com"; port=587, auth=true, user="user", pass="password", sslverify=false)
send(smtp, "from@example.com", "to@example.com", "Subject", "Hello, World!")
确保没有防火墙或代理阻止SSL连接。可以尝试直接使用curl
命令行工具测试SMTP服务器的连接:
curl --ssl-reqd --url smtp://smtp.example.com:587 --user user:password --mail-from from@example.com --mail-rcpt to@example.com --upload-file mail.txt
如果服务器使用的是自签名证书,可以将该证书添加到信任列表中:
using SMTPClient
# 设置自定义证书路径
ENV["CURL_CA_BUNDLE"] = "/path/to/custom_ca_bundle.crt"
smtp = SMTP("smtp.example.com"; port=587, auth=true, user="user", pass="password")
send(smtp, "from@example.com", "to@example.com", "Subject", "Hello, World!")
通过以上步骤,应该能够解决在使用SMTPClient.jl
发送电子邮件时遇到的SSL证书或SSH密钥问题。如果问题仍然存在,建议检查SMTP服务器的日志以获取更多详细信息。
领取专属 10元无门槛券
手把手带您无忧上云