Search code examples
ruby-on-railsportcapistranodigital-oceanmailgun

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?


Solution

  • 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