ryanb / letter_opener

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

Support sending emails with only the BCC field populated #158

Closed kylekeesling closed 5 years ago

kylekeesling commented 5 years ago

I have a situation where I want to send emails but protect all of the sender email addresses, hence BCCing everyone, but I noticed that the validation for this gem currently doesn't support that.

I've added an extra private method the check if the BCC is set and then adapted the smtp_envelope_to check to also take into account whether the BCC is set.

I've also added an additional spec that checks for this condition, and have been using the gem on my personal projects without any problems.

Please let me know how else I can help out or improve this PR.

nashby commented 5 years ago

@kylekeesling Hey! Thank you for the pull request. I've just tested mail gem like this:

mail = Mail.new do
  from    'mikel@test.lindsaar.net'
  bcc      'you@test.lindsaar.net'
  subject 'This is a test email'
  body    "123"
end

mail.smtp_envelope_to
 => ["you@test.lindsaar.net"]

So looks like it should work as it is. Do you get an exception in your app when you don't use to field?

kylekeesling commented 5 years ago

I've figured it out, the rubygem version of the gem, which I was using, doesn't have some of the latest updates.

Orginally I didn't dig to far into my stacktrace, I just cloned the repo and dug in, but when I actually looked at the full stacktrace I saw this:

screen shot 2018-12-09 at 8 58 31 pm

I immediately noticed that the validation logic doesn't match what's in the repo - The rubygem version just checks mail.to rather than the mail.smtp_envelope_to

Upon looking at the history of delivery_method.rb there was a patch committed by you fixing this in April, but the last gem was cut back in January.

So at any rate my PR is redundant and unnecessary, and if I just point my gemfile to the repo things are all good.

I am curious though - Is there any reason an updated gem hasn't been published yet?

nashby commented 5 years ago

@kylekeesling thanks for heads up. 1.7.0 is released! Please give it a try.

kylekeesling commented 5 years ago

Great - thanks!