How to use an external server with Ruby AMQP Carrot Library - ruby-on-rails

I am using the Ruby AMQP Carrot library and I am trying to talk to a test RabbitMQ server on a virtual machine. The AMQP port is open on the machine but I can't get Carrot to establish an external connection. I have tried the following:
Carrot.queue('message', :durable => true, :server => '192.168.162.176')
Carrot.queue('message', :durable => true, :host => '192.168.162.176')

I talked with the Carrot developer and this is the answer he gave me and it works great:
#client = Carrot.new(
:host => host,
:port => port.to_i,
:user => #opts['user'],
:pass => #opts['pass'],
:vhost => #opts['vhost'],
:insist => #opts['insist']
)
queue = #client.queue('foo')

Related

Mail not sending from ewebguru domain Rails

I have a domain techo.com (bought from ewebguru) and I'm tryng to send mail from my rails app but mail is not sending I'm using following code configuration in production and development :
{
:user => 'abcd#techo.com',
:password => '*********',
:domain => 'techo.com',
:port => 25,
:authentication => :none
}
somebody suggest me to do these :
User: mail id
Password: mail id password
SMTP Server: tecorb.com
SMTP Port: 25
POP Port: 110
SSL Authentication:None
I'm not getting how to configure these into my development.
Please suggest me.
As I see your code, you are missing :address key in the configuration. Address for ewebguru is mahanadi.ewebguru.net (may be this address can be change but same for my domain purchased from ewebguru). Try configuration like this :
ActionMailer::Base.smtp_settings = {
:user_name => 'abcd#techo.com',
:password => '*******',
:server => 'techo.com',
:address=>"mahanadi.ewebguru.net"
}
Hope this will work.

How to get IPN notification in PayPal on localhost

I am using Adaptive Payment in PayPal.
I am following the https://github.com/paypal/adaptivepayments-sdk-ruby.
All is working fine except I am not able to receive IPN notofications locally.
#api = PayPal::SDK::AdaptivePayments.new
#pay = #api.build_pay({
:actionType => "PAY",
:cancelUrl => "http://"+Rails.application.config.app_name+"/admin/dashboard",
:currencyCode => "USD",
:feesPayer => "SENDER",
:ipnNotificationUrl => "http://"+Rails.application.config.app_name+"/admin/receive_notification",
:receiverList => {
:receiver => [{
:amount => amount,
:email => #paypal_id }] },
:returnUrl => "http://"+Rails.application.config.app_name+"/admin/dashboard" })
So , how to receive notifications on localhost
Paypal will not be able to route to localhost to send the IPN. You would need to setup a publicly available domain name and the appropriate dns.
Localhost is always specific to your machine, you might be able to use dynamicdns but it would require network changes on your machine and network.

Sendgrid set up on Rails 4

I have a rails 4 app. I set up ActionMailer and I can send order confirmation emails via localhost and gmail.
I installed Sendgrid on Heroku and followed the set up instructions. I get a Net::SMTPSyntaxError (501 Syntax error
my environment.rb (i have sendgrid user/pwd in application.yml)
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com',
:enable_starttls_auto => true
}
in production.rb - the only actionamailer setting i have is this. I have this as a placeholder to put the real domain in later. I'm currently using herokuapp.com.
config.action_mailer.default_url_options = { host: 'localhost:3000' }
in my orders_controller within the order create method, I call the below.
AutoNotifier.orderconf_email(current_user, #order).deliver
auto_notifier.rb
class AutoNotifier < ActionMailer::Base
default from: "Test Email"
def orderconf_email(current_user, order)
#buyer = current_user
#order = order
mail(to: #buyer.email, subject: 'Thank you for your order.')
end
end
What am I missing? It works on localhost with gmail so I'm missing something in the sendgrid settings or in the default_url in production.rb file.
For posterity, here's a working setup for external SMTP in Rails on Heroku:
#config/environments/production.rb
config.action_mailer.smtp_settings = {
:address => "smtp.sendgrid.net",
:port => 587, # ports 587 and 2525 are also supported with STARTTLS
:enable_starttls_auto => true, # detects and uses STARTTLS
:user_name => ENV["SENDGRID_USERNAME"],
:password => ENV["SENDGRID_PASSWORD"], # SMTP password is any valid API key, when user_name is "apikey".
:authentication => 'login',
:domain => 'yourdomain.com', # your domain to identify your server when connecting
}
Change default from: "Test Email" to valid email address, even example#example.com.
I would just like to point out, this is for sending emails via SMTP. While this method is totally ok, you should also consider sending via the API.
To do this, you need to specify an interceptor. Luckily, there's a Gem that helps with that. Here's a good article showing how to use it.
https://rubyplus.com/articles/561-Sending-Emails-using-SendGrid-API-in-Rails-4-1
It took us a long time to resolve the issue when we tried to deploy the SMTP relay on heroku. It worked perfectly fine on local but when pushed we received socket errors and time out issues. Eventually got it working.
Important note: Make sure not to use starttls_auto and SSL/or TLS this causes open SSL issue.

Rails EOFError (end of file reached) when saving a devise user

I'm getting this error in production when trying to create a user (i'm using the devise gem).
EOFError (end of file reached):
I hit this problem before and it was due to my smtp settings using zoho mail.
I believe my configuration below is what fixed the problem:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.zoho.com",
:port => 465,
:domain => 'example.com',
:user_name => 'user#example.com',
:password => 'password',
:authentication => :login,
:ssl => true,
:tls => true,
:enable_starttls_auto => true
}
Now we've added SSL to the site and I believe that is what is causing this error to occur now.
Does anyone have any insight into this error or zoho mail smtp settings with SSL?
This error was caused by not having my config/initializers/devise.rb specifying the correct email address for config.mailer_sender.
Also! I made this additional mistake and had the same issue: I used my own domain instead of the mail server domain for the "domain" variable.
Your environment variable should be:
GMAIL_DOMAIN=gmail.com
Or for the example above:
:domain => 'gmail.com',
I found one cause for the error here => https://stackoverflow.com/a/40354121/6264112
But this didn't solve my issue. While I wasn't getting any errors, my emails were still not working through Zoho so I found another solution that works perfectly for my needs...
1) Connect Zoho to gmail using SMTP. I setup my zoho email as an alias for my personal gmail account so zoho emails are forwarded to gmail and I can reply to them IN gmail FROM my zoho email address. This should be done anyways so you never have to login to zoho. Just do all emailing from gmail.
2) Connect ActionMailer to gmail account NOT zoho.
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:user_name => ENV["gmail_username"],
:password => ENV["gmail_password"],
:authentication => :plain,
:enable_starttls_auto => true
}
Now, I just need to specify the to and from values in the mailer like so:
def notify_admin (message_details)
#message_details = message_details
mail(to: "jesse#mydomain.com", subject: "Contact form filled out by: " + message_details[:name], from: message_details[:email])
end
This works when I want to send emails to myself as is the example above when someone submits the contact form.
It ALSO works when I want to send an email from my domain such as when they fill out the lead magnet. All I did was switch the to: and from: addresses.
Here's a working pony gem call.
Pony.mail({
:to => 'apotonick#gmail.com',
subject: "Pony ride",
body: "Awesome!",
from: "nick#trb.to", # this MUST be the sending Zoho email.
:via => :smtp,
:via_options => {
:address => 'smtp.zoho.com',
:port => '465',
:enable_starttls_auto => true,
ssl: true,
:user_name => 'nick#trb.to', # MUST be identical to :from.
:password => 'yourStrongPw',
:authentication => :login,
}
})
I had this issue, and I tried everything and still couldn't figure out what the issue was.
Let's face it, it's a SH!t message. What I did find though I was running my rails app locally with POW and its actually a POW error.
When I run rails server and do the same thing that caused the error, I actually got the real error message and was able to find I hadn't setup my controller correctly

hostname does not match the server certificate - cannot send email

I am using Pony mail to send email messages (because I could never get ActionMailer to work on my local Windows box).
The code in my user_mailer.rb file include this call to the Pony.mail method:
Pony.mail({
:to => email_address,
:from => 'MyChairSales <support#mychairsales.com>',
:subject => subject,
:body => email_body,
:html_body => html_body,
:via => :smtp,
:via_options => {
:address => 'mail.mychairsales.com',
:port => '25',
:enable_starttls_auto => true,
:user_name => 'mychairs',
:password => 'thepassword',
:domain => "mychairsales.com" # the HELO domain provided by the client to the server
}
})
This was working (I have received email using this method) but is now failing with the error "hostname does not match the server certificate".
Here is the top of the stack trace:
["/usr/lib64/ruby/1.9.3/openssl/ssl-internal.rb:121:in `post_connection_check'",
"/usr/lib64/ruby/1.9.3/net/smtp.rb:585:in `tlsconnect'", "/usr/lib64/ruby/1.9.3
/net/smtp.rb:560:in `do_start'", "/usr/lib64/ruby/1.9.3/net/smtp.rb:519:in `start'",
"/home4/mychairs/ruby/gems/gems/mail-2.4.4/lib/mail/network/delivery_methods
/smtp.rb:144:in `deliver!'", "/home4/mychairs/ruby/gems/gems/mail-2.4.4/lib
/mail/message.rb:245:in `deliver!'", "/home4/mychairs/ruby/gems/gems/pony-1.4/lib
/pony.rb:166:in `deliver'", "/home4/mychairs/ruby/gems/gems/pony-1.4/lib
/pony.rb:138:in `mail'", "/home4/mychairs/rails_apps/chairsales/app/mailers
/user_mailer.rb:32:in `send_mail'", "/home4/mychairs/rails_apps/chairsales/app/mailers
/user_mailer.rb:23:in `send_password_reset_email'",...
Any guidance would be greatly appreciated!
A bit late but I also encountered this error but with the Ruby Mail gem. If your SMTP server supports TLS, it will attempt to use TLS and authenticate the SSL certificate. If the certificate is issued for a hostname other than the one used or if the certificate cannot be authenticated (for example if it's self-signed and you don't trust the CA), then it will fail with the error "hostname does not match the server certificate".
To get around it, use the :openssl_verify_mode option. This can be set to OpenSSL::SSL::VERIFY_NONE to do no verification of the certificate - it will still encrypt the SMTP session though. Or there are other options available within the OpenSSL library.
Using your example, it would be:
Pony.mail({
:to => email_address,
:from => 'MyChairSales <support#mychairsales.com>',
:subject => subject,
:body => email_body,
:html_body => html_body,
:via => :smtp,
:via_options => {
:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE,
:address => 'mail.mychairsales.com',
:port => '25',
:enable_starttls_auto => true,
:user_name => 'mychairs',
:password => 'thepassword',
:domain => "mychairsales.com" # the HELO domain provided by the client to the server
}
})
This also works for the Mail gem as well.

Resources