Skip to content

Embed email stylesheet directly in mailer header#2724

Open
mroderick wants to merge 1 commit into
masterfrom
feature/embed-email-css-in-style-block
Open

Embed email stylesheet directly in mailer header#2724
mroderick wants to merge 1 commit into
masterfrom
feature/embed-email-css-in-style-block

Conversation

@mroderick

@mroderick mroderick commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

Problem

Emails rely on premailer fetching /assets/email.css from the configured asset host. Even after #2715 switched the link from a hardcoded path to asset_path("email.css"), the resolved asset can still be stale or cached incorrectly in production. PR #2722 worked around this by inlining the social-button background colours directly in the template.

Solution

Move the entire email stylesheet into a <style> block inside app/views/shared_mailers/_header.html.haml. Premailer inlines these rules at delivery time, so the email carries its own CSS and no longer depends on resolving an external stylesheet.

Changes

  • Embed app/assets/stylesheets/email.css in the <head> of shared_mailers/_header.
  • Delete app/assets/stylesheets/email.css.
  • Remove the per-element inline background-color styles from shared_mailers/_social (now handled by the embedded .soc-btn.* rules).
  • Add a shared RSpec example that asserts the social-button colours are inlined, the external stylesheet link is absent, and the embedded <style> block is present.
  • Include the shared example in the five mailer specs that render shared_mailers/_social: WorkshopInvitationMailer, VirtualWorkshopInvitationMailer, EventInvitationMailer, MeetingInvitationMailer, and FeedbackRequestMailer.
  • Update the email assets README.

Verification

  • bundle exec rspec spec/mailers/ — 75 examples, 0 failures.
  • make test — 1158 examples, 0 failures.
  • bundle exec haml-lint app/views/shared_mailers/_header.html.haml — 0 lints.

@mroderick
mroderick marked this pull request as ready for review July 25, 2026 17:37
Eliminate the external `/assets/email.css` dependency for HTML emails by
deleting the stylesheet and embedding the full CSS in a `<style>` block
inside the shared mailer header partial.

This avoids stale/cached CSS and asset-host resolution issues. Premailer
inlines the `.soc-btn.*` rules, so the per-element inline `background-color`
styles added by the previous fix are no longer needed and have been reverted.

Also add a shared RSpec example that verifies every mailer rendering the
social footer inlines the five social-button colours, does not reference
`/assets/email.css`, and embeds the `<style>` block. Included in all five
affected mailer specs.

- Delete `app/assets/stylesheets/email.css`
- Embed CSS in `app/views/shared_mailers/_header.html.haml`
- Revert inline social-link colours from `app/views/shared_mailers/_social.html.haml`
- Update `app/assets/images/email/README.md`
- Add `spec/support/shared_examples/behaves_like_email_with_social_links.rb`
- Include shared example in `spec/mailers/*_invitation_mailer_spec.rb` and
  `spec/mailers/feedback_request_mailer_spec.rb`
@mroderick
mroderick force-pushed the feature/embed-email-css-in-style-block branch from 007d3e3 to 1d3522a Compare July 25, 2026 18:15
@mroderick
mroderick requested a review from olleolleolle July 25, 2026 18:19
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

Successfully merging this pull request may close these issues.

1 participant