Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4051408
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:11:28+00:00 2026-05-20T14:11:28+00:00

I am trying to set the :host for action mailer default url options. I

  • 0

I am trying to set the :host for action mailer default url options.

I have the below set in all the environment files

config.action_mailer.default_url_options = {
  :host => "localhost"
}

I want to make it more dynamic by providing the request host.

when I try to set it by

config.action_mailer.default_url_options = {
  :host => request.domain
}

OR

config.action_mailer.default_url_options = {
  :host => request.env["SERVER_NAME"]
}

It throws error… doesn’t recognize “request” object

is there any way I can set this to the request host, not by hardcoding…?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:11:28+00:00Added an answer on May 20, 2026 at 2:11 pm

    It is also possible to set a default host that will be used in all mailers by setting the :host option in the default_url_options hash

    in an application_controller.rb add:

    class ApplicationController < ActionController::Base
      def default_url_options
        { host: request.host_with_port }
      end
    end
    

    Source: https://edgeguides.rubyonrails.org/action_controller_overview.html#default-url-options

    Alternatively, you can pass the request when calling the mailer function from the controller

    class UserMailer < ActionMailer::Base
    
      def welcome_email(user, request)
        @user = user
        @url  = user_url(@user, host: request.host_with_port ) # do this for each link
        mail(:to => user.email, :subject => "Welcome to My Awesome Site")
      end
    end
    

    Source : https://guides.rubyonrails.org/action_mailer_basics.html#generating-urls-with-named-routes

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to set up my zend framework application on this host but I'm
I'm trying to set up my first repository on my host and am getting
I'm trying to set up my VPS to host two domains. The virtual host
I have for the last couple of hours been trying to set up a
I have been trying to set-up an Ajax Push Engine (APE) Server in a
I'm trying to set up a virtual host on my Mac OS X 10.7
I want that in my action method, my Request.Url.Host should be available. However I
I have Chromium 12.0.742.112 (90304) and I'm trying to set up a simple WebSocket
I'm trying to set up Selenium Grid 2 (Ubuntu-host for hub and Perl installed
trying to set up a simple embed box to echo url and randomize source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.