How does Actionmailer work without defining settings? - ruby-on-rails

I'm working on a rails project and can't figure out how the mail system works.
On the production server there is postfix installed, so I'm assuming thats how the emails are being sent (actually the headers show that it is postfix sending out the emails). However, in the application under config > environment > production.rb, there is nothing defining how to send the mail. There are no smtp settings, there is nothing saying its using sendmail or postfix, but the mails are being delivered. So how does the production server know to use postfix? I ask because the development server is using sendmail, so will anything need to be changed here for this to work or should it work out of the box (because it doesn't)?

Ok, so I figured out what was wrong, feel free to comment if you think my answer is not sufficient though or you have any feedback!
I found out from here that "Delivery defaults to an SMTP server running on your localhost on port 25." So on my production server it was working because postfix was installed. Where I was confused was staging, why wasn't sendmail working. I assumed sendmail was installed thats why! When I typed which sendmail, I got a result, so I assumed it was sendmail, but when I ran telnet <myhostname> 25 I got Exim 4.71! So a new assumption, sendmail is installed but not configured or setup on port 25, and exim is, so exim is handling mail.
I'm using this on amazon ec2 and just assumed that when I setup my instance, since its linux, it would have a mail server ready like I had on production. Obviously that was not a good assumption and I've now configured properly my prod, and I will try to use exim for staging since its already there.

Related

What port to use sending email with SMTP (mailgun) in rails app on production server (DigitalOcean)?

I have a rails app deployed at a digital ocean droplet configured with capistrano and mailgun, but I'm having trouble sending emails, task which I do using delayed_jobs. The thing is every time it tries to send an email I get connection timeout (verified using RAILS_ENV=production bin/delayed_jobs runin the server) and I found out that for some reason digital ocean does not allow from default for you to access through port 587 (and indeed, running telnet smtp.mailgun.org 587 takes a very long time to access) but apparently trough port 2525 you can (mailgun also supports that port and running telnet smtp.mailgun.org 2525 connects instantly!). But again, it still gives me connection timeout, so I'm kind of confused and don't know what to do. I'll probably send a ticket to DO asking to open port 587, until then do you have any ideas?
Digital Ocean blocks SMTP for safety reasons, based on the CAN SPAM Act (https://www.ftc.gov/tips-advice/business-center/guidance/can-spam-act-compliance-guide-business), so if you want to send emails using SMTP in their servers you'll need to send a ticket asking to unblock it with some infos about yourself so they verify your not just some crazy guy trying to flood people mail boxes or a robot.
Hope it helps! Good luck

rhc setup failure - msg "OpenShift server is not responding correctly"

Yesterday Aug 19 2014, I created a new scalable rails 4 application. Attempting to connect with rhc setup wizard tells me there is an error. Here is the output with sensitive data replaced respectively:
Using [myaccount] to login to myapp-mydomain.rhcloud.com
The OpenShift server is not responding correctly. Check that 'https://myapp-mydomain.rhcloud.com/broker/rest/api' is the correct URL for your server. The server may be offline or misconfigured.
Examining the app through openshift site, everything appears to be setup correctly. I compared it to another app which I do have running and other than the scalable feature, all settings seem to be OK.
I did see a message from OpenShift a few days ago that they were having some trouble, I am wondering if this is still the case and my app did not create correctly?
When you run rhc setup you shouldn't change the value of the server.
Use the default server hostname openshift.redhat.com
Use this command to use different account rhc setup --clean.

How do I make my ruby on rails app respond to external requests (visible to the public on the internet)?

Problem:
My rails app (on my local machine) only responds to requests sent from the same machine to localhost, 127.0.0.1, or my internal ip address. When I try to hit it using my internet ip or from any other machine, inside or outside of my network, it just times out. I'm on Mac OS 10.9.1, ruby 1.9.3, rails 4.0.0.
I've done a lot of searching but all I can find is problems where people didn't forward their ports or bind the right ip.
Here are the areas I've investigated:
Ports -
I've tried several different ports. I configured my router to forward every port I tried but got the same result. I thought maybe there was a problem with the router so I built a simple server in Java and bound all the same ports I was binding with my rails app. Sure enough, when I hit the Java app using my internet ip it worked just fine so the router/firewall/port forwarding isn't the problem. Also, I run an apache server on port 80 and that has never had any problems. I turned apache off and tried port 80 for my rails app but that didn't fix the problem.
Rails Server -
I started with WEBrick and I thought that perhaps there was some setting inside that blocked external requests. I searched google extensively and found nothing on that matter. Just to be safe I installed Thin and got the exact same result I did with WEBrick. One interesting thing is that when the rails server is started, the external request takes a long time to time-out, but the server console displays no output at all. However if I try to send the same request w/out starting the server at all it fails immediately.
User Permissions -
I started the server with root (i'm starting to just shoot in the dark here) and it had no effect.
Environment -
I was starting in development environment originally because I'm developing but just for fun I tried starting in production and it also made no difference.
PLEASE HELP ME SMART PEOPLE
Update:
I installed the app on my Ubuntu machine and it doesn't have this problem! So that suggests the problem may have something to do with Mac OS.
SOLVED:
It turns out that in the System Preferences -> Security & Privacy -> Firewall in Mac OS, it was somehow set to block incoming connections to Ruby 1.9.3. I must have accidentally set that some time ago.
The problem is you are probably trying to request the page from your local machine (or any computer on your local network, behind your firewall) to your public IP expecting a result... not unless you setup routes through your firewall for this (and not usually available on a consumer level router... linksys, dlink, etc)
So forward port 80 if you are using something like pow, or 3000 for web bricks default port to your local machine
Then have someone outside your local lan request your external (public) IP
This may be related: Rails 3.1 on Ubuntu 11.10 under VirtualBox very slow
Your mention of slowness combined with the use of webrick makes me think you've got some reverse-DNS lookup awfulness going on. A quick first step is hacking /etc/hosts to bypass this lookup.
The situation I dealt with on Ubuntu was solved in the short-term by hacking /etc/hosts. You could do this quick hack in order to see if it is indeed just webrick's reverse-DNS lookup. Edit /etc/hosts and add a line for the external user's IP address, something like this:
156.123.48.55 TestPerson
Replace the IP address with the tester's IP address. Since you said you can get the external request to hit an Apache server on port 80, you can grab their IP address from the Apache access logs if necessary, otherwise just ask the person testing.
You could also try a different web server, such as unicorn, which may help out. Add "gem unicorn-rails" to your Gemfile, run bundle install, and then (according to their docs), rails server will just use unicorn directly.
With any local server, you'll need to correctly configure port forwarding on your firewall. Like said by CaptChrisD, tests must be done by an external IP/browser (if you own a server, ssh on it, then w3m to test).
I already had same symptom (server started => timeout, server stopped => fail) and the origin was an issue with firewall configuration. I think it is your problem.
With MacOS, Pow is really awesome: installation is easy, no configuration required (no /etc/hosts…). Moreover, they give you a hook for external access to your virtualhosts (but you still need port forwarding on your firewall).
Otherwise, there is other solutions like Forward to do it without firewall configuration (30-days free trial).
Hope this helps!

Running Ruby on Rails app on server

I am using Aptana Studio 3 for development of ROR apps. I used run server command and it showed you can access your app on {http//0.0.0.0:3000/}, but when I try to access this URL, it tells me to check your Internet connection. I tried several other ports also but it is not working. I have created/modified the files necessary and migrated the database successfully too. Appreciate any help in running the app over the browser. I am currently using WeBrick Server.
so, in your title you say "on server". what does that mean? when you are running it on a different machine than your own, you need to use the address of that machine or it's domain name. keep in mind that firewall rules might prevent any connection to that server.
when you are ON the machine, via ssh for example, you can try calling the then "local" rails instance with curl http://localhost:3000/ to verify that it is running.

"getaddrinfo: Temporary failure in name resolution" in RoR application

I'm trying to retrieve emails from gmail using pop3 to my rails applicaiton. I get the error - "getaddrinfo: Temporary failure in name resolution" when i try to retrieve the email.
the weird thing is, it works when i try it at home but not at my university. i'm guessing it has something to do with the internet connection.
please help!
I had the same problem just started getting this error out of the blue in a RoR application that connects to an API using a RestClient running on a local virtual machine using Vagrant that I have as a development environment.
The only thing that fixed the issue was simply restarting my virtual machine. Just done a vagrant down & up command, then rackup and back in the game.
This generally means you aren't getting a response from DNS. Your university connection is probably behind a proxy preventing you from directly accessing the Internet. If so, this proxy must be specified in your code. Check your POP3 library documentation, or failing that, you may be able to use a library like socksify that redirects TCP connections through your SOCKS proxy.
Simple. You may be directed through a proxy server. Set up a new connection ,set up your college settings,restart your server and it should work.
ssh into your server and check if the machine is able to resolve the domain.
ping <your_site> should resolve the domain name to IP.
If its not resolving correctly, then there is some problem in your hosting service.
quick fix: You can manually map domain-to-ip in the etc/hosts file of your server.

Resources