How to set up a mail system of actions (should I register a domain)?

I am creating a simple non-profit application with Ruby on Rails. I need to configure the following settings to send email using Gmail:

Depot::Application.configure do config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { address:"smtp.gmail.com", port:587, domain:"domain.of.sender.net", authentication: "plain", user_name:"dave", password:"secret", enable_starttls_auto: true } end 

I am completely new to this and do not know what exactly I should do.

  • How to fill in the above settings if I have a gmail account? Do I have to buy a domain and can I buy it from Google to use the settings above?
  • Is it better to set up a mail server on my PC? I looked, although this tutorial, but as far as I understand, I still need to buy a domain.

Also, as said here :

Setting up a mail server is a complex process, including a number of different programs, each of which must be correctly configured.

Because of this and my weak skills, I am looking for the simplest solution.

I read the action rails guide and got an idea of ​​what these parameters are used for, but everything around Gmail and the mail server are not entirely clear.

+6
source share
2 answers

The configuration of your mailer should / can be defined in both development and production . The purpose of this configuration is that when you configure this parameter when you use actionmailer , these SMTP parameters will be used. You may have a simple mail program, for example:

Mailer

 class UserMailer < ActionMailer::Base default :from => DEFAULT_FROM def registration_confirmation(user) @user = user @url = "http://portal.herokuapp.com/login" mail(:to => user.email, :subject => "Registered") end end 

controller

  def create @title = 'Create a user' @user = User.new(params[:user]) if @user.save UserMailer.registration_confirmation(@user).deliver redirect_to usermanagement_path flash[:success] = 'Created successfully.' else @title = 'Create a user' render 'new' end end 

So what happens here is that when you use the create action, the UserMailer . Looking at the aforementioned UserMailer, it uses ActionMailer as a base. Below is the SMTP setting, which can be defined both in config/environments/production.rb and development.rb

You will have the following:

  config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => 'smtp.gmail.com', :port => 587, :domain => 'gmail.com', :user_name => ' EMAIL_ADDRESS@gmail.com ', :password => 'pass', :authentication => 'login', :enable_starttls_auto => true } 

If you want to define SMTP settings in design mode, you will replace

 config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' } 

with

 config.action_mailer.default_url_options = { :host => 'IP ADDRESS HERE:3000' } 

This should be a detailed enough explanation to start with you in the right direction.

+15
source

This answer worked for me in development as soon as I changed it to

 authentication: 'plain' 

and turned on

 config.action_mailer.raise_delivery_errors = true 

in my development environment.

+2
source

All Articles