Could someone please help me to troubleshoot/configure sending email with ssl/tls please ?
- Ruby : 3.1.2
- Rails : 6.1.7
- net-smtp: 0.3.3
- docker image : 3.1-slim
- My own organisation SMTP serveur that responds like this on port 25
250-servername.mydomain
250-PIPELINING
250-SIZE
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
I confirm without starttls it's fine
config.action_mailer.smtp_settings = {
address: ENV.fetch('MAIL_SMTP_SERVER'),
port: ENV.fetch('MAIL_SMTP_PORT', '25'),
domain: ENV.fetch('MAIL_DOMAIN'),
openssl_verify_mode: OpenSSL::SSL::VERIFY_NONE
}
But I do want to use starttls
or tls
so i configure like this
config.action_mailer.smtp_settings = {
address: ENV.fetch('MAIL_SMTP_SERVER'),
port: ENV.fetch('MAIL_SMTP_PORT', '25'),
domain: ENV.fetch('MAIL_DOMAIN')
}
- I put my
.pem
certificates files in/etc/ssl/certs
folder (certificates provided by my organisation and generated by our own PKI) - but I still have this error
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 peeraddr=xx.xx.xx.xx:25 state=error: certificate verify failed (self signed certificate)
/myapp/lib/tasks/notif.rake:16:in `block (2 levels) in <top (required)>'
/myapp/bin/rails:5:in `require'
/myapp/bin/rails:5:in `<top (required)>'
/myapp/bin/spring:10:in `require'
/myapp/bin/spring:10:in `block in <top (required)>'
/myapp/bin/spring:7:in `<top (required)>'
- With this other combination
ssl: true,
enable_starttls_auto: false,
openssl_verify_mode: OpenSSL::SSL::VERIFY_PEER,
ca_file: "/etc/ssl/certs/ca-certificates.crt",
I have this error :
/bundle/gems/net-protocol-0.1.3/lib/net/protocol.rb:46:in `connect_nonblock': SSL_connect returned=1 errno=0 peeraddr=10.19.1.33:25 state=error: wrong version number (OpenSSL::SSL::SSLError)
How can I check if i use correct version ?
Any idea please ?
Here it is how i test sending my mail.
in irb inside my container:
irb(main):005:0> mailer = ActionMailer::Base.new
=> #<ActionMailer::Base:0x00000000062fe8>
irb(main):006:0> mailer.smtp_settings
=> {:address=>"xxxx.xxxxx.com", :port=>"25", :domain=>"xxxxxx", :ssl=>true, :enable_starttls_auto=>false, :openssl_verify_mode=>1, :ca_file=>"/etc/ssl/certs/ca-certificates.crt"}
irb(main):007:0> mailer.mail(from: 'xxxxx', to: 'xxxxx',
subject: 'test', body: "Hello, you've got mail!").deliver
I tried lots of combinations but nothing works.
I'm confused and i just wanted to know if there is a problem on client side or server side