Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Iphone not display attachments sent by python 2.7.x

Dear fellow developers

I have a problem where attachments sent by Python 2.7.5 smtplib combined with MIMEBase are discarded/not displayed by the email client on iOS for iPad and iPhones (but are received and shown on all other platforms).

I'm using program code straight from the python docs site example.

msgOther = MIMEBase(mimeMainType, mimeSubType)
msgOther.set_payload(binData)
encoders.encode_base64(msgOther)
msgOther.add_header(u'Content-Disposition', u'attachment', filename=binDisplayName)
MessageData.attach(msgOther)


where binData is a .pdf file generated by Qt4
and mimeMainType = application,
and mimeSubType = pdf,
and binDisplayName = BaseNameOfFileWithoutPath

Email sent by code above is received fine and well on: Microsoft Windows XP/7/8 with Outlook express and Exchange. Thunderbird on Linux desktop, GMail Webmail, GMail POP3 client on Android mobile, Standard email client in Samsung mobile devices, Mac OSX Desktop standard mail client.

HOWEVER on iPhone and iPad devices, the attachments are not shown. Only the main (HTML)body and inline images I send are shown but a .pdf or a .docx as attachment are not shown at all.

The main body part is set to alternative or mixed (I tried both but without result). I also tried multiple or single attachements without result where this works always all the time fine on the other platforms.

Does somebody else has the same experience?

Note:I'm running Python 2.7.5 on Fedora Linux 20.

like image 890
thedax Avatar asked Oct 29 '25 20:10

thedax


1 Answers

Instead of:

msg = MIMEMultipart('alternative')

Use:

msg = MIMEMultipart('mixed')
like image 102
Khr Avatar answered Oct 31 '25 10:10

Khr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!