Log In

This guide helps to configure your Ruby On Rails application to send outgoing messages using your SMTP2GO account. We will be using Action Mailer, the part of the Rails library that allows to send emails from the application using mailer classes and views.

Step 1

Please change the following in this script:

sender@example.com: the sender’s email address.

USERNAME: your SMTP2GO username.

PASSWORD: your SMTP2GO password.

yourdomain.com: your domain name.

Step 2

Create the Mailer called “UserMailer” with the action “sendMail” using following command:

$ rails generate mailer UserMailer sendMail

Step 3

Modify the “sendMail” action according to your requirement. Below is the example content of the/app/mailers/user_mailer.rb:

class UserMailer < ActionMailer::Base
default from: "sender@example.com"
def sendMail(email)
@greeting = "Hi"

mail to: email, subject: "Your Subject"
end
end

Step 4

You may modify the text content of the message at /app/views/user_mailer/sendMail.text.erb. You may also create the HTML version of the message by creating /app/views/user_mailer/sendMail.html.erb file and add the required html content. Below is the example content of the text message:

, This is a text message.

Step 5

Configure the SMTP settings in the development.rb or production.rb or test.rb configuration file according to your requirement. These files are located at /config/environments/ folder.

config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: "mail.smtp2go.com",
port: 2525, # 8025, 587 and 25 can also be used.
domain: "yourdomain.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: "USERNAME",
password: "PASSWORD"
}

Step 6

You may test the settings by running the following command from rails console.

UserMailer.sendMail("recipient@example.com").deliver

Please note: as SMTP2GO allows a maximum of 20 concurrent SMTP connections, if you expect that your Ruby script could potentially make more than 20 concurrent SMTP connections, we recommend that you make use of a mail server such as Postfix, as an intermediary: http://www.smtp2go.com/docs/postfix/
You would then set your Ruby of Rails app to send emails via your Postfix mailserver, which would in turn route its emails through your SMTP2GO account.

Ready for better email delivery?

Try SMTP2GO free for as long as you like:

Try SMTP2GO Free → Paid plans available for over 1,000 emails/month.