ruby-on-railsemailactionmailer

How to include urls when evoking ActionMailer::Base.mail


I am sending an email with Rails like so:

ActionMailer::Base.mail(
  from: "me@example.com",
  to: "you@example.com",
  subject: "test",
  body: "test"
).deliver

I want the body to include [test](https://ham.com), but this markdown is not parsed, and <a href="https://ham.com">test</a> doesn't work either.

How can I format my url so it gets formatted properly?


Solution

  • If you want it sent as HTML then you need to provide the Content-Type header (content_type: "text/html"), although it's better to follow the normal approach of a mailer subclass, and using templates.