You can pass the request when calling the mailer function from the controller--
class UserMailer < ActionMailer::Base
def welcome_email(user, request)
UserMailer.default_url_options[:host] = request.host_with_port #option1
@user = user
@url = user_url(@user, host: request.host_with_port ) #option2 (do this for each link)
mail(:to => user.email,
:subject => "Welcome to My Awesome Site")
end
end
In the above code request.host_with_port
is the "example.com"
for your case.
So above is the more dynamic way to provide the request host as you can see that you can pass the request when calling the mailer function from the controller.
This is the source that you can check -
Generating-urls-in-action-mailer-views.
This is also the explantion at action-mailer-default-url-options-and-request-host which is marked here for the answer to read.