Friday 15 March 2013

Simple Ruby email out localhost:25, no OpenSSL::SSL::SSLError, no tlsconnect error

Notes:
  1. This skips the common OpenSSL::SSL::SSLError / tlscommon errors somehow, see below for error output.
  2. DON'T use pony's "smtp" hash option, it has the same problem. Notice it is missing here!
Steps:
  1. gem install pony
  2. take below code 
    1. put in ~/bin/mail_test.rb
    2. tweak for your environment
    3. chmod +x ~/bin/mail_test.rb 

https://github.com/pcharlesleddy/misc/blob/master/mail_test.rb

#!/usr/bin/ruby

require 'rubygems'
require 'pony'

mystring = "a\nb\nc"

Pony.mail(:to => 'abc@efg.org', :from => 'me@example.com', :subject => 'Test mail script', :body => 'Hello there.', :attachments => {"mail_test.txt" => File.read("/home/me/bin/mail_test.rb"), "mystring.txt" => mystring})


Common, irritating tlscommon error:

/usr/lib/ruby/1.8/openssl/ssl-internal.rb:123:in `post_connection_check': hostname was not match with the server certificate (OpenSSL::SSL::SSLError)
from /usr/lib/rvm/gems/ruby-1.9.3-p194/gems/mail-2.5.3/lib/mail/core_extensions/smtp.rb:17:in `tlsconnect'
from /usr/lib/ruby/1.8/net/smtp.rb:562:in `do_start'
#!/usr/bin/ruby
from /usr/lib/ruby/1.8/net/smtp.rb:525:in `start'
from /usr/lib/rvm/gems/ruby-1.9.3-p194/gems/mail-2.5.3/lib/mail/network/delivery_methods/smtp.rb:136:in `deliver!'
from /usr/lib/rvm/gems/ruby-1.9.3-p194/gems/mail-2.5.3/lib/mail/message.rb:245:in `deliver!'
from /usr/lib/rvm/gems/ruby-1.9.3-p194/gems/pony-1.4/lib/pony.rb:166:in `deliver'
from /usr/lib/rvm/gems/ruby-1.9.3-p194/gems/pony-1.4/lib/pony.rb:138:in `mail'

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...