ruby on rails - Why Action Mailer generated URLs are not reaching the site? Could it be my mail subdomain config? -
i have rails app hosted in 'www.example.com'. objective send email containing link url pointing specific place in app.
the issue: in development works ok in production mailer link redirects server dns can't found.
when checked url generated noticed points to: 'http://email.mail.example.com' instead of 'http://example.com' (where i'd have expected point out to) haven't been able change or figure out why happens. current code is:
config/environments/production.rb
config.action_mailer.default_url_options = { host: 'example.com' } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :authentication => :plain, :address => "smtp.mailgun.org", :port => 587, :domain => env['mailgun_domain'], :user_name => env['mailgun_username'], :password => env['mailgun_password'] } the link in mailer view
<%= link_to 'click here', url_for(@post) %> i've tried
given 'email.mail' bit in url i'm assuming there's issue domain dns configuration. following mailgun's advice (when adding domain them) i'm using subdomain ('mail') transactional emails. suggested added cname record (host: email.mail.example.com, value: mailgun.org) when setting up.
so i've tried changing record or deleting without success.
also, i've changed host value below seems regardless url starts 'email.mail'
config.action_mailer.default_url_option = { host: 'mail.example.com' } i've tried changing link see if provided other path like:
post_url(@post) i wonder if can me this. should host settings @ production.rb different given i'm using subdomain 'mail' transactional emails? i've been trying find answer online haven't been able find similar cases.
additional info app supposed send email users every time there's new post
my mailer code
class postsmailer < applicationmailer def new_post_notification(user, post) @user = user @post = post mail to: "#{@user.email}", subject: "#{@post.user.username.capitalize} posted" end end my mailer view
<body> <h2><%= @post.user.username.capitalize %> has posted</h2> <p>check <%= @post.user.username.capitalize %>'s <%= link_to 'new post here', url_for(@post) %></p> </body>
i wrong on happening here. urls generated helpers ok problem mailgun (as transactional email providers) generate made-up hashed urls direct user site while being able track if users clicking or opening emails.
in mailgun hashed urls appended, default, subdomains set in email domain. prefix appended url should reach site.
it still not clear problem it's mailgun one. moved sendgrid added white-labeled domain subdomain , worked fine. not mention easier verify.
sendgrid has added benefit can white-label link different subdomain worked perfectly.
i asked mailgun reason why happened , still waiting answer. i'm assuming there's else add in domain's dns settings.
i'll post here answer in case ran similar problem.
Comments
Post a Comment