Comments (13)
Hi.
Thanks for reporting this issue. Please open a PR. I'll check this afternoon what SendGrid recommends.
Envoyé de mon iPhone
Le 9 janv. 2014 à 06:29, Stephen Bussey [email protected] a écrit :
I have been using this module with SendGrid and just started sending attachments. Oddly, my excel files were "corrupted" and easily fixed by excel, but the byte size did not match what I sent it (~100 bytes more).
I dug into the SendGridService and see this line:
$post->set('files[' . $attachment->filename . ']', $attachment->getRawContent() . ';type=' . $attachment->type);
However, this is not correct as the type is being appended to the end of the file. Removing this fixed my corruption issue. I recommend removing this line from production because ";type=whatever" is not a standard file protocol. I don't mind doing this and pull requesting.—
Reply to this email directly or view it on GitHub.
from slmmail.
We're assuming the file type is set (see here). I think we should check if the filetype is set, because you can send attachments with and without explicit file types.
If you check the api docs you can "Send a test with attachment" and "Send a test specifying the file content type by appending ‘;type=’ to the file name". Both should be valid.
@sb8244 do you set the filetype explicitly or not? Like this:
$attachment = new MimePart(fopen('/path/to/test.pdf', 'r'));
$attachment->type = 'application/pdf';
from slmmail.
Hi Jurian,
I set the filetype explicitly by doing:
$excelPark->type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
However, if you do not set a filetype on a Zend part, it becomes 'application/octet-stream', which would actually still be viable for an excel file.
Actually I see the bug now, "Send a [text?] specifying the file content type by appending ';type=' to the file NAME". However, SlmMail appends it to the file content.
from slmmail.
I have contacted the SendMail support to ask for some help with this. Meanwhile I will create a PR that will set the mime type only if it is available from the mime part object.
@sb8244 the cUrl "@" annotation is a method to embed file contents from your local file system and (as far as I know) the "@file/name.ext" is substituted with the raw file data when cUrl processes the request. In this example:
-F files[attachment.pdf][email protected];type=application/pdf
The first attachment.pdf
between brackets is the file name, the second attachment.pdf
should (again, afaik) be substituted with the raw file data. If you look at the raw POST data in the manual it should result in some part that looks like this:
Content-Disposition: form-data; name="files[myfile]"; filename="myfile"
Content-Type: application/octet-stream
file with stuff in it
I am not sure how to get this working, perhaps we should look at how ZF2 processes these requests.
from slmmail.
The problem I'm still seeing is that the type is getting tacked onto the
file content instead of the name. Logically this doesn't make sense because
the file contents could happen to naturally have the right content to
trigger the behavior, which the API creators at SendGrid wouldn't allow.
SendGrid docs say it needs to be on the name. I will test this on my local
copy against SendGrid to see if it works.
On Jan 15, 2014 4:51 AM, "Jurian Sluiman" [email protected] wrote:
I have contacted the SendMail support to ask for some help with this.
Meanwhile I will create a PR that will set the mime type only if it is
available from the mime part object.@sb8244 https://github.com/sb8244 the cUrl "@" annotation is a method
to embed file contents from your local file system and (as far as I know)
the "@file/name.ext" is substituted with the raw file data when cUrl
processes the request. In this example:-F files[attachment.pdf][email protected];type=application/pdf
The first attachment.pdf between brackets is the file name, the second
attachment.pdf should (again, afaik) be substituted with the raw file
data. If you look at the raw POST data in the manualhttp://sendgrid.com/docs/API_Reference/Web_API/mail.html#wrapper_9cb432583ceaf8911c9f978a1a09de16it should result in some part that looks like this:Content-Disposition: form-data; name="files[myfile]"; filename="myfile"
Content-Type: application/octet-stream
file with stuff in it
I am not sure how to get this working, perhaps we should look at how ZF2
processes these requests.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/65#issuecomment-32347317
.
from slmmail.
Now I have digged through the way the http client is preparing the body of the request, I see what's happened. First, for normal post data, there aren't set any headers in the encoding of the part. However, for the files, the type of the headers is injected into the encoding method.
So, if we don't use post but files instead, I think this is going to work.
@sb8244 if you have a look later if this is the correct idea?
from slmmail.
Browsing the docs of Zend\Http\Client, there is also a setFileUpload()
available which helps to set files for the files parameter container. In fact it exactly does what I suggested above.
from slmmail.
I think it's even less drastic. 3 lines after the post URL (on my phone so
hard to link), the files property is set. However, the set is placing the
type on content instead of the title. Literally just have to move the
content type into the file name part of that line. Definitely still use
getPost.
On Jan 15, 2014 11:05 AM, "Jurian Sluiman" [email protected] wrote:
Browsing the docs of Zend\Http\Clienthttp://zf2.readthedocs.org/en/latest/modules/zend.http.client.advanced.html#file-uploads,
there is also a setFileUpload() available which helps to set files for
the files parameter container. In fact it exactly doeshttps://github.com/zendframework/zf2/blob/master/library/Zend/Http/Client.php#L1008-L1030what I suggested above.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/65#issuecomment-32375196
.
from slmmail.
SendGrid files aren't sent using http files protocol, so we have to still
use post.
On Jan 15, 2014 11:09 AM, "Stephen Bussey" [email protected] wrote:
I think it's even less drastic. 3 lines after the post URL (on my phone so
hard to link), the files property is set. However, the set is placing the
type on content instead of the title. Literally just have to move the
content type into the file name part of that line. Definitely still use
getPost.
On Jan 15, 2014 11:05 AM, "Jurian Sluiman" [email protected]
wrote:Browsing the docs of Zend\Http\Clienthttp://zf2.readthedocs.org/en/latest/modules/zend.http.client.advanced.html#file-uploads,
there is also a setFileUpload() available which helps to set files for
the files parameter container. In fact it exactly doeshttps://github.com/zendframework/zf2/blob/master/library/Zend/Http/Client.php#L1008-L1030what I suggested above.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/65#issuecomment-32375196
.
from slmmail.
Can the bug code at least be removed from the current version? Every time I composer update I have to reset the bug line.
from slmmail.
@juriansluiman, can you make a PR as you seem to have play with that?
from slmmail.
Can the offending code please be removed from the library? It literally serves no purpose and just causes issues for SendGrid. In no way is it working as intended, and serves no function otherwise as of now. I'm going to PR it and hope that you accept, otherwise I am going to have to fork and use a non-updating repo as my library.
from slmmail.
See #70 from here on out
from slmmail.
Related Issues (20)
- PHP Version HOT 1
- get was unable to fetch or create an instance for getServiceLocator HOT 1
- Mailgun as email transporter HOT 4
- Search API for Mandrill HOT 1
- ElasticEmail error when unauthorized
- laminas? HOT 5
- Transfer to JouwWeb organization
- Target PHP 7.2 and above
- Tag a release HOT 6
- Document how to use with Mezzio HOT 1
- Release 3.0
- Companies using SlmMail HOT 4
- SSLv3 failure at Mandrill HOT 4
- SES - Enhancement request: switch to latest Aws ZF2 module HOT 11
- Send not return ID of message HOT 3
- Elastic Email error method HOT 2
- Unable to enable crypto on TCP connection api.mailgun.net HOT 4
- ElasticMail: enable custom headers HOT 1
- Zend 2 app + SendGrid emails sent are blocked by Gmail HOT 4
- Mailgun: support templates HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from slmmail.