fix: add proper HTML structure to email templates to reduce spam score#1548
fix: add proper HTML structure to email templates to reduce spam score#1548Yash-Chauhan22 wants to merge 3 commits into
Conversation
- Add .env from template for local development - Add GSOC.md contribution tracker and reference guide - Update .vscode/settings.json with Go/Node portable paths - Remove obsolete version field from docker-compose.yaml
Fixes apache#783 Emails sent by Answer were being flagged by SpamAssassin with the TVD_PH_BODY_META_ALL rule due to missing HTML document structure (DOCTYPE, html, head, meta charset tags) in the email body. Changes: - Add MIME-Version header and explicit UTF-8 charset to email sender - Wrap all 8 email body templates (en_US) with proper HTML document structure including DOCTYPE declaration, meta charset=UTF-8, and viewport meta tag This ensures email clients and spam filters correctly identify the content type and encoding, reducing the spam score.
- Fix incorrect comment on VerifyUrlExpired (was 'email send', now accurately describes URL expiry verification) - Replace vague 'kit service', 'email config', 'save code' etc. with clear, descriptive sentences following Go doc conventions - All 15 exported symbols now have accurate, meaningful documentation
|
Thanks for working on this. The overall direction makes sense to me. Using a complete HTML document structure for HTML emails is a common practice and should help reduce compatibility issues with mail clients and spam filters. However, I think this PR needs a few adjustments before it can be merged.
The following files/changes are not related to the email spam-score fix and should be excluded:
This PR should focus only on the email template / email sending behavior.
gomail.NewMessage() already uses UTF-8 by default, and SetBody("text/html", body) already writes the HTML part with Content-Type: text/html; charset=UTF-8. gomail also automatically writes Mime-Version: 1.0 if it is not already present. The current change may cause duplicate or malformed headers: m.SetHeader("MIME-Version", "1.0") m.SetBody("text/html; charset=UTF-8", body) In gomail, the auto-check uses the exact header key Mime-Version, while this PR sets MIME-Version, so gomail may still add its own Mime-Version header. Also, gomail appends ; charset=UTF-8 when writing the body part, so passing text/html; charset=UTF-8 to SetBody may result in duplicated charset So I suggest keeping the original call: m.SetBody("text/html", body)
Currently only i18n/en_US.yaml is updated. Since email templates are translated based on the user language, other locales will still send partial HTML fragments without DOCTYPE, html, head, meta, and body. If we keep the HTML document structure inside i18n templates, then the email templates across locales should be updated consistently, or at least all supported email template bodies should use the same HTML document wrapper. In short, I agree with the main fix, but the PR should be narrowed down to the email template changes, avoid manual MIME header changes, and remove unrelated development-environment/doc changes. |
Summary
Fixes #783
Emails sent by Answer were being flagged by spam filters (Apache SpamAssassin)
with the
TVD_PH_BODY_META_ALLrule due to missing proper HTML documentstructure in the email body.
Root Cause
The
TVD_PH_BODY_META_ALLrule fires when an HTML email lacks:<!DOCTYPE html>declaration<html>,<head>,<body>tags<meta charset>tagChanges
internal/service/export/email_service.go: AddedMIME-Version: 1.0header and explicit
charset=UTF-8inContent-Typefor all outgoing emailsi18n/en_US.yaml: Wrapped all 8 email body templates with proper HTMLdocument structure (
<!DOCTYPE html>,<html>,<head>,<meta charset='UTF-8'>,<meta name='viewport'>,<body>)Testing
Verified Go build passes with no errors. Fix can be validated using
mail-tester.com or Apache SpamAssassin locally.