SMTPClient.jl
SMTPClient.jl copied to clipboard
SSL certificate problem: self-signed certificate
I am trying to send an email with my ProtonMail account, I have bridge installed which runs an smtp server on my local machine at 127.0.0.1:1025 and uses SSL for security, the bridge then relays my email to ProtonMail servers which don't support smtp directly for security reasons, thus they created the bridge.
When I do this I get his error when running send:
* processing: smtps://127.0.0.1:1025
* Trying 127.0.0.1:1025...
* Connected to 127.0.0.1 (127.0.0.1) port 1025
* CAfile: /opt/homebrew/Cellar/julia/1.9.2/share/julia/cert.pem
* CApath: none
* SSL certificate problem: self-signed certificate
* Closing connection
┌ Error: ERROR:
│ exception =
│ curl_easy_perform() failed: SSL peer certificate or SSH remote key was not OK
│ Stacktrace:
...
So I need to figure out how to solve this certificate issue?
Here is my code:
url = "smtps://127.0.0.1:1025"
opt = SendOptions(
isSSL=true,
username=ENV["BRIDGE_UNAME"],
passwd=ENV["BRIDGE_PASS"],
verbose=true
)
function send_email2(name, sender, receiver, subject, message, attachments)
global url, opt
to = ["<$receiver>"]
from = "$name <$sender>"
replyto = sender
body = get_body(to, from, subject, message; replyto, attachments)
resp = send(url, to, from, body, opt)
end
I have a solution just add cacert to the SendOptions struct
mutable struct SendOptions
isSSL::Bool
username::String
passwd::String
cacert::String
verbose::Bool
end
and then use a default value of LibCURL.cacert
function SendOptions(; isSSL::Bool = false, username::AbstractString = "",
passwd::AbstractString = "", cacert = LibCURL.cacert, verbose::Bool = false, kwargs...)
...
And then we can do this:
if options.isSSL
@ce_curl curl_easy_setopt curl CURLOPT_USE_SSL CURLUSESSL_ALL
@ce_curl curl_easy_setopt curl CURLOPT_CAINFO options.cacert
end
Yeah, that sounds like a decent design. Would you make a PR? I'd probably add cacert
as the last parameter in the list, after verbose
.