Site is in sub-directory /app
In development.rb:
config.action_mailer.default_url_options = {
host: 'localhost:3000/app'
}
Url generated in the mailer item_url(1):
localhost/item/1, it should be: localhost:3000/app/item/1
How do I replace localhost with localhost:3000/app?
This is in Rails 4.1.15.
To expand on tadman's comment... Your host should only have the 'localhost' portion and a separate port option:
config.action_mailer.default_url_options = {
host: 'localhost',
port: 3000
}
As for making the app load under /app:
config.relative_url_root = "/app"
(See see Rails app in a subdirectory for details)
Using script_name did the trick:
config.action_mailer.default_url_options = {
host: 'localhost',
port: 3000,
script_name: '/app'
}
Related
This is the first time I'm working with actionmailer in production.
Earlier I deployed an App to a VPS server. I haven't assigned a domain to it yet so it is only an IP address.
I configured the action mailer settings, but I'm curious about this line:
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }can I use the Ip address of the server instead of { host: 'localhost', port: 3000 }or does the server act as a localhost after the app is deployed with this setting?
Here is the setup code in the production.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: ENV["SMTP_ADDRESS"],
user_name: ENV["SMTP_USER"],
password: ENV["SMTP_PASSWORD"],
domain: "gmail.com",
port: 587,
authentication: :login,
enable_starttls_auto: true
}
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
Once you have configured this and you use these settings to send the mail via gmail server. The default url will be used as the domain name of website/application like say for forgot password to users.
http://localhost:3000/forgot_password?email="fd#ds.com"
You should be changing this to the domain name or the ip where the application code is hosted. localhost is used only for development setups.
Missing host to link to! Please provide the :host parameter, set
default_url_options[:host], or set :only_path to true
I randomly get this error at time, generally restarting the server fixes the issue for a while, and then it shows up again.
I have added
config.action_mailer.default_url_options = "localhost:3000", in the development and test.rb files.
Also, I have used include Rails.application.routes.url_helpers
in one module to get access to the routes, I read this could be the reason I get these errors but removing it will leave me with no access to the routes.
The module is for the datatables gem.
For Rails 5, use:
Rails.application.routes.default_url_options[:host] = "XXX"
You can put this in a config/environments/ file (or any other initializer), or e.g. at the beginning of config/routes.rb.
You should write in the following way
For Development(development.rb)
config.action_mailer.default_url_options = { :host => "localhost:3000" }
In production (production.rb)
config.action_mailer.default_url_options = { :host => "myproductionsite.com" }
I had a similar error. The problem is in your configuration.
Try rewriting your configuration for your development.rb and test.rb like this:
config.action_mailer.default_url_options = { host: "localhost", port: 3000 }
Also check that your configuration in production.rb is written correctly like this:
config.action_mailer.default_url_options = { host: 'myherokuapp.herokuapp.com' }
You have updated the default url options for action mailer.
URL helpers will take the option from action_controller settings.
config.action_controller.default_url_options = .....
BR
please help solve the problem.
i use webrick server on localhost. in development.rb i registered:
config/enviroments/development.rb:
Rails.application.configure do
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
end
i use gem devise. and i user 'forgot youre password'-function (devise-recoverable module). the result did not get to the email message. but where can I find a mark(log) that was an attempt to send a letter? whether there is a directory where they are stored?
You will need to edit your config/environments/development.rb file.
Here's something to get you started, add this to that file:
# port 3000 or whatever port you are using for your localhost
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.raise_delivery_errors = false
config.action_mailer.delivery_method = :smtp
# this line is what you want to be true, else you won't get messages!
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: 'gmail.com' # or to whatever domain your email is
authentication: "plain",
enable_starttls_auto: true,
user_name: 'my_gmail_or_other_username',
password: 'my_gmail_or_other_password'
}
Now, when you are moving towards production or even just pushing it to a public repository you obviously don't want to hardcode the username and password (for security purposes). For this I suggest you look up how to use environmental variables. The Figaro gem might also come in handy here and is another option.
This is the default 'smtp' way, there are other methods, such as the use of a gem as specified by the earlier answer.
try gem mailcatcher for development purpose.
http://mailcatcher.me/
github: https://github.com/sj26/mailcatcher
This gem will provide you a tab in browser where all your emails will be there unless you delete them.
I have problem with sending emails from localhost.
it was working on linux and now I'm trying to run my app on mac and it doesn't work already.
I have an error:
ArgumentError in Devise::RegistrationsController#create
SMTP-AUTH requested but missing user name
in config/environments/development.rb:
#Action Mailer config
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.delivery_method = :smtp
# Send email in development mode.
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: "587",
domain: "mail.google.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USER_ID"],
password: ENV["GMAIL_PASSWORD"]
}
My env variables are good, I tried put my credential into code as well and it still doesn't work :/
I checked similiar topics but didn't found the solution.
What can I try?
I read:
I tried put my credential into code as well and it still doesn't work :/
But have you tried replacing your var env with your gmail id/password like this ?
#Action Mailer config
**********
user_name: "my_username",
password: "my_password"
}
Just to be sure.
Ok, solved.
credentials didn't work because I havn't restarted my server (stupid laziness)
my env vars didn't work because I've puted them into ~.profile but it work in ~.bash_profile, that was helpful (I use OS X Yosemite).
I am trying to send emails via action mailer. I have the same config for production and for development:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'ee.ex.my_domain.net',
port: 465,
domain: 'my_domain',
user_name: 'email#my_mail.com',
password: 'my_pass',
authentication: :ntlm,
enable_starttls_auto: true
}
config.action_mailer.default_url_options = { :host => "localhost:3000" }
The only difference between development and production config is the host. For production I use an existing url, on my local machine it works ok but when I try it on the server I got this error:
Net::SMTPSyntaxError (504 5.7.4 Unrecognized authentication type)
I have had this error before on my local machine but I changed the authentication to :ntml and it works fine.
UPDATE
tried in server console (code from ntlm gem github page)
require 'ntlm/smtp'
smtp = Net::SMTP.new('smtp.example.com')
smtp.start('localhost.localdomain', 'Domain\\User', 'Password', :ntlm) do |smtp|
smtp.send_mail(mail_body, from_addr, to_addr)
end
but have the same error