Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devise emails sending as plaintext. #38

Open
dgobhai opened this issue Oct 14, 2016 · 7 comments
Open

Devise emails sending as plaintext. #38

dgobhai opened this issue Oct 14, 2016 · 7 comments

Comments

@dgobhai
Copy link

dgobhai commented Oct 14, 2016

attempting to isolate the problem, I have disabled tracking

# config/environments/production.rb
Rails.application.configure do
  config.action_mailer.delivery_method = :sparkpost

# config/initializers/sparkpost_rails.rb
SparkPostRails.configure do |c|
  c.api_key       = ENV.fetch('SPARKPOST_API_KEY')
  c.sandbox       = false
  c.track_clicks  = false
  c.track_opens   = false
  c.transactional = false
end

Emails sent with our custom mailer are sending fine, however Devise generated emails: Forgot password, are sending as plaintext when they should be html.

I'm trying to figure out what devise is doing with type, still looking...

@dgobhai
Copy link
Author

dgobhai commented Oct 14, 2016

Continuing investigation on a new rails app: https://github.com/dgobhai/sparkpost

Docs say config file/block is not necessary:

Note that an initializer file is not required to use this gem. If an initializer is not provided, default values will be used. See "Additional Configuration" below for a list of all the default settings.

but it seems to be. Here is the error output from heroku log when attempting to send a forgot password email from devise:

2016-10-14T21:45:58.699558+00:00 app[web.1]: <p>Your password won't change until you access the link above and create a new one.</p>
2016-10-14T21:45:58.699559+00:00 app[web.1]: 
2016-10-14T21:45:58.699842+00:00 app[web.1]: Completed 500 Internal Server Error in 428ms (ActiveRecord: 5.4ms)
2016-10-14T21:45:58.701412+00:00 app[web.1]: 
2016-10-14T21:45:58.701416+00:00 app[web.1]: NoMethodError (undefined method `html_content_only' for nil:NilClass):
2016-10-14T21:45:58.701418+00:00 app[web.1]:   vendor/bundle/ruby/2.2.0/gems/sparkpost_rails-1.4.0/lib/sparkpost_rails/delivery_method.rb:164:in `prepare_inline_content_from'

@dgobhai
Copy link
Author

dgobhai commented Oct 14, 2016

After adding the config:

SparkPostRails.configure do |c|
  c.api_key       = ENV.fetch('SPARKPOST_API_KEY')
  c.sandbox       = true
end

The logs show an html email being sent:

2016-10-14T21:59:41.902213+00:00 app[web.1]: Sent mail to [email protected] (459.2ms)
2016-10-14T21:59:41.902218+00:00 app[web.1]: Date: Fri, 14 Oct 2016 21:59:41 +0000
2016-10-14T21:59:41.902218+00:00 app[web.1]: From: [email protected]
2016-10-14T21:59:41.902221+00:00 app[web.1]: Reply-To: [email protected]
2016-10-14T21:59:41.902222+00:00 app[web.1]: To: [email protected]
2016-10-14T21:59:41.902222+00:00 app[web.1]: Message-ID: <5801554d6cf2f_33fb7085b62e8549db@3c07599c-3ddb-40b8-b22c-31d4017fade2.mail>
2016-10-14T21:59:41.902223+00:00 app[web.1]: Subject: Reset password instructions
2016-10-14T21:59:41.902224+00:00 app[web.1]: Mime-Version: 1.0
2016-10-14T21:59:41.902224+00:00 app[web.1]: Content-Type: text/html;
2016-10-14T21:59:41.902225+00:00 app[web.1]:  charset=UTF-8
2016-10-14T21:59:41.902225+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2016-10-14T21:59:41.902226+00:00 app[web.1]: 
2016-10-14T21:59:41.902226+00:00 app[web.1]: <p>Hello 
...

But the email that comes across is plain text with html tags still in it:

Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="UTF-8"
To: [email protected]
Date: Fri, 14 Oct 2016 21:59:41 +0000
Message-ID: <5801554d6cf2f_33fb7085b62e8549db@3c07599c-3ddb-40b8-b22c-31d4017fade2.mail>
From: [email protected]
MIME-Version: 1.0
...
<p>Hello!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><a href="http://sparkpostbox.com/users/password/edit?reset_password_token=foo">Change my password</a></p>

@dgobhai
Copy link
Author

dgobhai commented Oct 17, 2016

The issue with the configuration file is:

  def self.configure
    self.configuration ||= Configuration.new
    yield(configuration)
  end

except .configure is never called, unless you add a configuration file - which the docs say is not needed. Not sure what you'd like to change: code or docs.

@RomanKapitonov
Copy link

The same issue for me, any workarounds?

@AfolabiOlaoluwa
Copy link

Team please respond to to this. Same with me.

@johnjansen
Copy link

include both a text and html template and things should all work just fine

@webzorg
Copy link

webzorg commented May 23, 2018

So, just add this to the initializer

SparkPostRails.configure do |c|
  ...
  c.html_content_only = true
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants