Page MenuHomePhabricator

Fix sending email as user / via sendgrid.
Needs ReviewPublic

Authored by klimek on Aug 15 2014, 5:54 PM.
Tags
None
Referenced Files
F18654551: D10278.id24751.diff
Mon, Sep 22, 2:04 PM
F18590860: D10278.diff
Sep 12 2025, 7:20 AM
F18590742: D10278.id.diff
Sep 12 2025, 7:01 AM
F18048745: D10278.id.diff
Aug 3 2025, 1:59 PM
F18048714: D10278.id24751.diff
Aug 3 2025, 1:50 PM
F18047886: D10278.id.diff
Aug 3 2025, 1:12 PM
F18018696: D10278.diff
Aug 2 2025, 7:07 PM
F17732526: D10278.id24751.diff
Jul 20 2025, 5:04 AM
Subscribers

Details

Reviewers
epriestley
Group Reviewers
Blessed Reviewers
Summary

As we're sending emails for users without actually being them, we need
to pretend to be a mailing list (otherwise DMARC will kill the emails). The
way to do that is setting the List-Id field.

PHPMailer/SMTP also needs 'quoted-printable', otherwise integration with
sendgrid will double all line breaks (see
http://stackoverflow.com/questions/6276181/extra-newlines-in-plain-text-emails-sent-via-sendgrid).

Test Plan

Running on our production instance.

Diff Detail

Repository
rP Phabricator
Branch
fix-mail-as-user
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 2248
Build 2252: [Placeholder Plan] Wait for 30 Seconds

Event Timeline

klimek retitled this revision from to Fix sending email as user / via sendgrid..
klimek updated this object.
klimek edited the test plan for this revision. (Show Details)
klimek added a reviewer: epriestley.
  • Is disabling metamta.can-send-as-user a reasonable alternative to "List-Id"?
  • Why aren't you using the PhabricatorMailImplementationSendGridAdapter if you're using SendGrid? (Because of T3435?)
  • The quoted-printable thing is specifically a bug/behavior unique to SendGrid, right, and has gone at least 3 years without being fixed? Are you tied to SendGrid? We've seen other long-lived/odd behavior from SendGrid (T3435, T4199) and now recommend MailGun in the documentation.
  • Is disabling metamta.can-send-as-user a reasonable alternative to "List-Id"?

Well, no :) Then the email is not from the user.

  • Why aren't you using the PhabricatorMailImplementationSendGridAdapter if you're using SendGrid? (Because of T3435?)

Yes, partly. The sendgrid API is basically very limited and their answer is "use smtp".

  • The quoted-printable thing is specifically a bug/behavior unique to SendGrid, right, and has gone at least 3 years without being fixed?

I must admit that I don't know whether the quoted-printable thing is a sendgrid, phpmailer, or different level problem. The one line of 'quoted-printable' is also pretty simple for us to keep in the branch until we can switch off SendGrid :)

Are you tied to SendGrid?

Not particularly :) I found it's working well for us, and has a pretty generous free tier (25k mails + incoming email forwarding, which we need)

We've seen other long-lived/odd behavior from SendGrid (T3435, T4199) and now recommend MailGun in the documentation.

I can take a look at MailGun. Not sure their free tier (10k mails / mo) is enough for us, I'll check. Thx for the pointer.

I pulled the quoted-printable bit into D10303, since another install hit this issue. Hopefully this doesn't break like 3 other mailers. :/

Awesome. So what about the rest? I'm happy with keeping this in our branch (I think it's never led to a merge problem), but I also think it's super useful to at least have documented somewhere if we don't want to put this into the main branch (it took me a day to figure out what the right solution is (after talking to some of my colleagues), so if somebody else hits this they'll probably also be wasting a lot of time on it; figuring out why mail is rejected is about the least fun thing one can work on).