Skip to content

Commit

Permalink
Added mailkick_unsubscribe_headers method
Browse files Browse the repository at this point in the history
  • Loading branch information
ankane committed Jan 14, 2024
1 parent 5bcba4a commit 4ef6db8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ which copies the view into `app/views/mailkick`.
For one-click unsubscribe headers ([RFC 8058](https://datatracker.ietf.org/doc/html/rfc8058)), add to your mailer:

```ruby
headers["List-Unsubscribe-Post"] = "List-Unsubscribe=One-Click"
headers["List-Unsubscribe"] = "<#{mailkick_unsubscribe_url(@user, "sales")}>"
mailkick_unsubscribe_headers(@user, "sales")
```

## Bounces and Spam Reports
Expand Down
5 changes: 5 additions & 0 deletions lib/mailkick/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ def mailkick_unsubscribe_url(subscriber, list, **options)
token = Mailkick.generate_token(subscriber, list)
mailkick.unsubscribe_subscription_url(token, **options)
end

def mailkick_unsubscribe_headers(subscriber, list, **options)
headers["List-Unsubscribe-Post"] = "List-Unsubscribe=One-Click"
headers["List-Unsubscribe"] = "<#{mailkick_unsubscribe_url(subscriber, list)}>"
end
end
end
3 changes: 1 addition & 2 deletions test/internal/app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ class UserMailer < ActionMailer::Base
default from: "from@example.com"

def welcome
headers["List-Unsubscribe-Post"] = "List-Unsubscribe=One-Click"
headers["List-Unsubscribe"] = "<#{mailkick_unsubscribe_url(params[:user], "sales")}>"
mailkick_unsubscribe_headers(params[:user], "sales")
mail to: "test@example.org", subject: "Hello"
end
end

0 comments on commit 4ef6db8

Please sign in to comment.