Pièce jointe envoyée par mail généré par python non visible sur iphone
Bonjour,
J'envoie des mails automatiques en python qui contiennent des pièces jointes.
Quand je lis le mail sur outlook, un webmail, aucun souci, j'ai bien le mail et la pièce jointe.
Quand je le lis directement sur le compte mail depuis un iphone, ipad ou mac, il m'affiche bien la présence d'une pièce jointe mais celle-ci reste non visible.
Le problème est donc à priori spécifique à apple...
Pour géré mes pièce jointes, j'utilise une fonction classique :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| def FICHIER( chemin ):
"""Guess the content type based on the file's extension. Encoding
will be ignored, altough we should check for simple things like
gzip'd or compressed files."""
ctype, encoding = mimetypes.guess_type(chemin)
if ctype is None or encoding is not None:
# No guess could be made, or the file is encoded (compresses), so
# use a generic bag-of-bits type.
ctype = 'application.octet-stream'
maintype, subtype = ctype.split('/', 1)
if maintype == 'text':
fp = open(chemin)
# Note : we should handle calculating the charset
msg = MIMEText(fp.read(), _subtype=subtype)
fp.close()
elif maintype == 'image':
fp = open(chemin, 'rb')
msg = MIMEImage(fp.read(), _subtype=subtype)
fp.close()
elif maintype == 'audio':
fp = open(chemin, 'rb')
msg = MIMEAudio(fp.read(), _subtype=subtype)
fp.close()
elif maintype != None and subtype != None:
fp = open(chemin, 'rb')
msg = MIMEBase(maintype, subtype)
msg.set_payload(fp.read())
fp.close()
# Encode the payload using Base64
Encoders.encode_base64(msg)
else:
fp = open(chemin, 'rb')
msg = MIMEBase('application', "octet-stream")
msg.set_payload(fp.read())
fp.close()
# Encode the payload using Base64
Encoders.encode_base64(msg)
# Set the filename parameter
fichier = os.path.basename(chemin)
msg.add_header('Content-Disposition','attachment',filename=fichier)
return msg |
et pour ajouter le fichier dans mon mail :
Code:
1 2 3 4
|
msgRoot = MIMEMultipart('related')
msgRoot['Subject'] = u"Envoie de mail avec pièce jointe"
msgRoot.attach(FICHIER('monfichier.pdf')) |
Est-ce que quelqu'un aurait une idée ?
Merci d'avance,