Search code examples
ruby-on-rails-4mailman

How to send reply mail to particular mail using mailman server in ruby on rails


I want to send acknowledge mail to a particular mail using mailman server. I tried many times to do that. But I did not get any solutions. Please advise me to do the thing.


Solution

  • This is very simple:

    I like to have an initializer for handle this, like so:

    config/initializers/setup_email.rb

    if Rails.env.production?
     ActionMailer::Base.smtp_settings = {
      :user_name => ENV['SENDGRID_USERNAME'],
      :password => ENV['SENDGRID_PASSWORD'],
      :domain => ENV['SENDGRID_DOMAIN'],
      :address => "smtp.sendgrid.net",
      :port => 587,
      :authentication => :plain,
      :enable_starttls_auto => true
     }
    end
    

    And then for the production and development environments you have to do something like so:

    config/environments/production.rb

    config.action_mailer.default_url_options = { host: "http://www.example.com" }
    config.action_mailer.asset_host = "http://www.example.com"
    

    As for the development environment I recommend you install the mailcatcher gem:

    $ gem install mailcatcher
    

    Once is installed, run the mailcatcher command:

    $ mailcatcher
    

    This will enable a web page on http://127.0.0.1:1080 to where every email will be send and you'll be able to preview them. Just make sure your have the following configuration

    config/environments/development.rb

    config.action_mailer.default_url_options = { host: "localhost:3000" }
    config.action_mailer.asset_host = "http://localhost:3000"
    
    #mailcatcher configs
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.smtp_settings = { :address => "localhost", :port => 1025 }
    

    Then you should be fine!