Skip to content

[Mailer] [Mailgun] Fix outlook sender #51773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2023

Conversation

Romanavr
Copy link
Contributor

@Romanavr Romanavr commented Sep 28, 2023

Q A
Branch? 6.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #51596
License MIT

This PR solves the problem related to displaying the sender in the OutLook email client when sending an email from a subdomain.
Check more details by following these links:
https://serverfault.com/questions/1097879/sender-and-from-header-domain-mismatch-causes-malformed-display-in-outlook
https://stackoverflow.com/questions/28401673/removing-on-behalf-of-when-sending-mail-using-mailgun/45445015#45445015

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 6.4 branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@carsonbot
Copy link

Hey!

Thanks for your PR. You are targeting branch "6.4" but it seems your PR description refers to branch "6.4 for bug fixes".
Could you update the PR description or change target branch? This helps core maintainers a lot.

Cheers!

Carsonbot

@xabbuh xabbuh added the Mailer label Sep 28, 2023
@carsonbot carsonbot changed the title [Mailer-Mailgun] Fix outlook sender [Mailer] [Mailer-Mailgun] Fix outlook sender Sep 28, 2023
@Romanavr Romanavr changed the base branch from 6.4 to 6.3 September 28, 2023 15:23
@nicolas-grekas nicolas-grekas changed the title [Mailer] [Mailer-Mailgun] Fix outlook sender [Mailer] [Mailgun] Fix outlook sender Sep 29, 2023
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 6.3 Sep 29, 2023
@nicolas-grekas
Copy link
Member

Thank you @Romanavr.

@svendecabooter
Copy link

It seems like this change is causing issues for me, when sending mails to Gmail accounts via Mailgun.
I am getting errors like the following in Mailgun:

5.7.1 This message is not RFC 5322 compliant. There are multiple Sender\n5.7.1 headers. To reduce the amount of spam sent to Gmail, this message has\n5.7.1 been blocked.

After some digging, it seems my sent message contains 2 sender headers, one capitalized and one not:

Sender: mail@example.com
sender: mail@example.com

I am still trying to figure out where the capitalized "Sender" header gets added in my flow, but haven't pinned that down yet.
However I'd like to point this issue out, for people encountering the same problem.
If I have more information that is relevant, I will update here.

I am not familiar enough with email headers, but if it is considered best practice to capitalize them, then maybe the custom header added via this change should also be capitalized?

@Romanavr
Copy link
Contributor Author

It seems like this change is causing issues for me, when sending mails to Gmail accounts via Mailgun. I am getting errors like the following in Mailgun:

5.7.1 This message is not RFC 5322 compliant. There are multiple Sender\n5.7.1 headers. To reduce the amount of spam sent to Gmail, this message has\n5.7.1 been blocked.

After some digging, it seems my sent message contains 2 sender headers, one capitalized and one not:

Sender: mail@example.com
sender: mail@example.com

I am still trying to figure out where the capitalized "Sender" header gets added in my flow, but haven't pinned that down yet. However I'd like to point this issue out, for people encountering the same problem. If I have more information that is relevant, I will update here.

I am not familiar enough with email headers, but if it is considered best practice to capitalize them, then maybe the custom header added via this change should also be capitalized?

I just tested - everything is ok for me, what transport type are you using? API?

@svendecabooter
Copy link

@Romanavr yes API.

@Romanavr
Copy link
Contributor Author

@Romanavr yes API.

I was able to reproduce. Indeed, good point about capitalize the header.

@Romanavr
Copy link
Contributor Author

Romanavr commented Oct 12, 2023

@svendecabooter Please try 52017#fix and let me know if it works for you

nicolas-grekas added a commit that referenced this pull request Oct 12, 2023
This PR was squashed before being merged into the 6.3 branch.

Discussion
----------

[Mailer] Capitalize sender header for Mailgun

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #51773 (comment)
| License       | MIT

This fix resolves the duplicate header issue.
Without a fix, using API & HTTP transport type, emails could leave with double headers, causing problems for some email providers, for example, the problem was reproduced with Gmail:
`5.7.1 This message is not RFC 5322 compliant. There are multiple Sender 5.7.1 headers. To reduce the amount of spam sent to Gmail, this message has 5.7.1 been blocked.`

Moreover, I found that changes to HTTP transport type were not necessary since this problem could be solved by simply adding a sender, so I reverted everything for HTTP transport type.

Commits
-------

eb394bb [Mailer] Capitalize sender header for Mailgun
@spajxo
Copy link
Contributor

spajxo commented Jan 29, 2024

Hello,

I have come across a problem caused by this change.

The header h:Sender is added here as UnstructuredHeader.

When it is added into payload here, sometimes it encodes incorrectly

The issue occurs only in some cases when using Sender Address with name part with diacritics, because of the difference in encoding of UnstructuredHeader and MailboxHeader.

example:

$unstructuredHeader = new UnstructuredHeader('From', '"Klaudie Šulcová" <foo@bar.com>');
$mailboxHeader = new MailboxHeader('From', new Address('foo@bar.com', 'Klaudie Šulcová'));

$unstructuredHeader->getBodyAsString(),  // ""Klaudie =?utf-8?Q?=C5=A0ulcov=C3=A1=22?= <foo@bar.com>"
$mailboxHeader->getBodyAsString()           // "Klaudie =?utf-8?Q?=C5=A0ulcov=C3=A1?= <foo@bar.com>"

I discovered this problem because some mailservers complained about the Sender header being invalid.

A simple solution to fix this problem would be adding the h:Sender header as MailboxHeader here

$headers->addMailboxHeader('h:Sender', $envelope->getSender());

I'll send a PR

nicolas-grekas added a commit that referenced this pull request Jan 29, 2024
This PR was submitted for the 6.4 branch but it was squashed and merged into the 6.3 branch instead.

Discussion
----------

[Mailer] [Mailgun] Fix sender header encoding

| Q             | A
| ------------- | ---
| Branch?       | 6.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #51773 (comment)
| License       | MIT

This adjustment fixes a problem with header encoding in MailgunApiTransport.
The issue occurs only in some cases when using Sender Address with name part with diacritics, because of the difference in encoding of UnstructuredHeader and MailboxHeader.

It changes the method used to add header `h:Sender` so that MailboxHeader is used.

Commits
-------

0f3b2f7 [Mailer] [Mailgun] Fix sender header encoding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sending through Mailgun mailer with a subdomain results in "on behalf of" in sender name
6 participants