ryanb / letter_opener

Preview mail in the browser instead of sending.
MIT License
3.71k stars 236 forks source link

Does not open an email in browser #178

Closed palexvs closed 4 years ago

palexvs commented 4 years ago

MacOs Catalina 10.15.5

#Gemfile.lock
  rails (~> 5.2.3)
  letter_opener (1.7.0)
  launchy (~> 2.2)
#config/environments/development.rb
  config.action_mailer.delivery_method = :letter_opener
  config.action_mailer.perform_deliveries = true
  config.action_mailer.default_url_options = { host: "localhost:3000" }
  config.action_mailer.raise_delivery_errors = false
#app/mailers/user_report_mailer.rb

class UserReportMailer < ApplicationMailer
  layout "mailer"

  def index
    @users = User.active

    mail(to: "aa@test.to", subject: "Test")
  end
end

In one console I run Rails server:

> bundle exec rails server -p 3000

In another, I open the Rails console and try to send an email:

> bundle exec rails c
dev> UserReportMailer.index.deliver_now

  Rendering user_report_mailer/index.html.erb within layouts/mailer
   (0.6ms)  SELECT COUNT(*) FROM "users" WHERE "users"."active" = $1 [["active", true]]
  Rendered user_report_mailer/index.html.erb within layouts/mailer (2.5ms)
UserReportMailer#index: processed outbound mail in 178.8ms
Sent mail to  (5.6ms)
Date: Mon, 17 Aug 2020 21:06:13 -0700
From: from@test.to
Message-ID: <5f3b53b57d676_84783fcaf882ffd452640@Alexs-MacBook-Pro.local.mail>
Subject: ["aa@test.to"] Test
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
      /* Email styles need to be inline */
    </style>
  </head>

  <body>
    Active users: 9
  </body>
</html>

=> #<Mail::Message:70140853342340, Multipart: false, Headers: <Date: Mon, 17 Aug 2020 21:06:13 -0700>, <From: from@test.to>, <Bcc: >, <Message-ID: <5f3b53b57d676_84783fcaf882ffd452640@Alexs-MacBook-Pro.local.mail>>, <Subject: ["aa@test.to"] Test>, <Mime-Version: 1.0>, <Content-Type: text/html>, <Content-Transfer-Encoding: 7bit>>

But nothing opens in browser

nashby commented 4 years ago

Can you please provide a sample application that reproduces the error?

bjer commented 4 years ago

I had no issue with letter_opener on Catalina 10.15.6, rails 5.2.4.3, letter_opener 1.70 and launchy 2.5.0. Mailer called from rake task. Also worked in rails console.

nashby commented 4 years ago

thanks @bjer! Closing this for now. @palexvs feel free to ping me if you still have an issue and have sample app that reproduces it.

Winslett commented 3 years ago

If you run into this problem, you'll need to change the OS's default file-opener for .html files to be your web browser.

pospieszynski commented 3 years ago

For anyone struggling with _letteropener not working in some cases, I think I've knocked out the problem. It's not really related to this gem directly although the error message could be a bit better.

Debugging steps:

As you can see, you probably have not configured the from address for that particular email

In my case error was located in Devise configuration which used to lack sender config. Adding sth like this in initialized solved the problem:

Devise.setup do |config|
  config.mailer_sender = "your@email.com" # change to your valid email
end

Hope that helped someone

dannieltung commented 2 years ago

Anyone still facing this issue? On Terminal it seems to be working but the email is not poping up on Chrome's Tab.... Rendering user_mailer/welcome.html.erb within layouts/mailer Rendered user_mailer/welcome.html.erb within layouts/mailer (Duration: 1.0ms | Allocations: 252) UserMailer#welcome: processed outbound mail in 7.9ms Delivered mail 626dcf043ce90_51643fc55a01a040688ab@Danniels-MBP.mail (5.8ms) Date: Sat, 30 Apr 2022 21:06:28 -0300 From: dwftung@gmail.com To: danniel@gmail.com Message-ID: 626dcf043ce90_51643fc55a01a040688ab@Danniels-MBP.mail Subject: Cop or Drop Mime-Version: 1.0 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html>=0D

=0D =0D =0D =0D =0D =0D =0D =0D

Seja bem-vindo danniel@gmail.com!

=0D

Segue c=C3=B3digo de valida=C3=A7=C3=A3o: 776142

=0D =0D =0D => #, , , >, , , , >