yagmail
yagmail copied to clipboard
Content-Type: application/octet-stream for the csv files or Content-Disposition: attachment for the attachments
Hi, thank you for the amazing repo!
Instead of Content-Type: text/csv is it possible to set Content-Type as application/octet-stream for the attached csv files?
thank you Radoslaw
Hey, thanks for posting. I'm not sure why you would want that :)? It would help understanding how it would fit in the code.
Thank you Pascal for your prompt reply. Based on my understanding all csv files send via yagmail are detected as 'Content-Type: text/csv; name="some_filename.csv"' which is very nice feature because the content of the csv file is directly displayed inline in the body of the email.
But for my case I would like to display the attachments as the attachements. See the screenshot.

Thank you. Have a wonderful weekend! Radoslaw
Hi Radoslaw, just a guess... but are you mentioning the csv in contents or in attachments? In case you cannot get it to work with using attachments, it's most likely a bug. You too, enjoy the weekend :-)
Hi Pascal, yes I'm using attachments. See the code and zipped csv.
smtp.send(to=myemail, subject='test1', attachments='/path/123_ARIADNA-10-2017.csv' )
123_ARIADNA-10-2017.csv.zip
Thank you Radoslaw
Could you try to see if it works for you with yagmail-0.10.209?
pip uninstall yagmail && pip install --no-cache yagmail
No luck.
print(yagmail.__version__)
shows: 0.10.209
but I'm still getting the same results.
here are the raw content of the email:
--===============6190816825531352608==
Content-Type: multipart/alternative;
boundary="===============3425160699749472352=="
MIME-Version: 1.0
--===============3425160699749472352==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
--===============3425160699749472352==
Content-Type: multipart/related;
boundary="===============6154958952834555628=="
MIME-Version: 1.0
--===============6154958952834555628==
Content-Type: text/html; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
--===============6154958952834555628==--
--===============3425160699749472352==--
--===============6190816825531352608==
Content-Type: text/csv; name="123_ARIADNA-10-2017.csv"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Um96cG9jesSZY2llIHJvem1vd3k7TnVtZXIgxbpyw7NkxYJvd3k7QWRyZXMgbnVtZXJ1IMW6csOz
ZMWCb3dlZ287TnVtZXIgZG9jZWxvd3k7Um9kemFqIHBvxYLEhWN6ZW5pYTtDemFzIHBvxYLEhWN6
ZW5pYTtLd290YSBuZXR0bw0KMjAxNy0xMS0xMSAxMToxMToxMTsxMTExMTExMTExMTvFgcOzZMW6
LCB1bC4gMTExMTExMTExMTEgMi82OzExMTExMTExMTExO2tvbcOzcmtvd2U7MDowMDozNjswLDEw
MDAwMA0K
--===============6190816825531352608==--
I think I misunderstood the question!
For me in gmail, the csv shows just fine (not inline, but as attachment). But you want application/octet-stream as type? Why? Isn't the type of a .csv file "text/csv"?
Yes it works on gmail web client. The issue has something to do with the mac Mail App (desktop & ios) If you have macOS or iPhone when you will see that the csv attachments are displayed inline.
See the part of the raw source, email send via perl's MIME::Lite + Net:SMTP, which works:
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="123_ARIADNA-10-2017.csv"
Content-Type: application/octet-stream
based on my research adding Content-Disposition: attachment with Content-Type: application/csv should work
in the meantime a small amendment in sender.py did the trick ;)
if content_object['encoding'] != 'base64' or content_object['sub_type'] =='csv':
content_object['main_type'] = 'application'
content_object['sub_type'] = 'octet-stream'
Had the same problem, still a bug at v0.10.212. @radoslawoska fix works. CSV attachments sent with yagmail can't be read properly on gmail client running on apple systems on current version. Its really important ^^. cheers!
I have missed this one, thanks for bringing it back to attention. Feel free to make a PR as you've already found the fix, I'd gladly accept it and put it on pypi!
thank you, PR created
I am able to force application/octet-stream by patching mimetypes.guess_type
import mimetypes
def guess_type(*args, **kwargs):
return (None, None)
mimetypes.guess_type = guess_type
This is a very ugly hack though...