Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Mailer] Fix attachment content encoding for SendgridTransport#32645

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
chalasr wants to merge1 commit intosymfony:4.3fromchalasr:sendgrid-api-attach

Conversation

@chalasr
Copy link
Member

@chalasrchalasr commentedJul 21, 2019
edited
Loading

QA
Branch?4.3
Bug fix?yes
New feature?no
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed ticketsn/a
LicenseMIT
Doc PRn/a

Using the SendgridTransport (HTTP), emails cannot be sent as soon as they have attachments.
This is due to Sendgrid not supporting line breaks in base64 encoded content (encoding is considered invalid, which results in a 400 response from the Sendgrid API).

PHP Fatal error: Uncaught Symfony\Component\Mailer\Exception\TransportException: Unable to send an email: The attachment content must be base64 encoded. (code 400). in ./vendor/symfony/sendgrid-mailer/Http/Api/SendgridTransport.php:51 Stack trace: #0 ./vendor/symfony/mailer/Transport/Http/Api/AbstractApiTransport.php(59): Symfony\Component\Mailer\Bridge\Sendgrid\Http\Api\SendgridTransport->doSendEmail(Object(Symfony\Component\Mime\Email), Object(Symfony\Component\Mailer\DelayedSmtpEnvelope))

It has been reported multiple times in sendgrid official integrations, and the answer was always "please open a PR to document this in our troubleshooting section, strict base64 is required".
See limitation documented herehttps://github.com/sendgrid/sendgrid-ruby/blob/master/USE_CASES.md#adding-attachments and a bug reportsendgrid/sendgrid-php#272.

}

/**
* @internal

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

it doesn't make sense to me to have an internal method for cross component uses
if we think this is a needed API, we should commit to it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I'm against making this public, that leaks internal information I don't want to expose.

$filename =$headers->getHeaderParameter('Content-Disposition','filename');
$disposition =$headers->getHeaderBody('Content-Disposition');
// Sendgrid does not accept line breaks for base64 encoded attachments
$content ='base64' ===$attachment->getEncoding() ?base64_encode($attachment->getBody()) :$attachment->bodyToString();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

this looks like bypassing the encoding abstraction
can't we instead decide for the encoding earlier? (a line-break-less variant of base64)

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We can have a specific base64 encoder, but it can’t be done earlier since the email is not aware of the transport. The transport would have to set the encoder on each attachment (DataPart instance) at send time

nicolas-grekas added a commit that referenced this pull requestJan 4, 2020
…tuart Fyfe)This PR was squashed before being merged into the 4.3 branch.Discussion----------[Mailer] Remove line breaks in email attachment contentLine breaks are not allowed in attachment content when sending over theAPI.| Q             | A| ------------- | ---| Branch?       | 4.3| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Tickets       |Fix#33671,Closes#32645| License       | MIT| Doc PR        |This is a fix for#33671. Send grid's API throws a 400 error when sending email attachments with default base64 encoding.Removing the line breaks resolves this issue.Commits-------a28a7f9 [Mailer] Remove line breaks in email attachment content
@chalasrchalasr deleted the sendgrid-api-attach branchJanuary 4, 2020 15:45
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot left review comments

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

Assignees

No one assigned

Projects

None yet

Milestone

4.3

Development

Successfully merging this pull request may close these issues.

4 participants

@chalasr@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp