-
Notifications
You must be signed in to change notification settings - Fork 57
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fails when attaching HTML file #18
Comments
the 'double' attachments showing up in Gmail seems to be a bug in Gmail ... the message source appears to be correct :) |
The problem is that the code makes a wrong assumption in line 291 of envelope.py (https://github.com/tomekwojcik/envelopes/blob/master/envelopes/envelope.py#L291). for part in self._parts:
type_maj, type_min = part[0].split('/')
# Small correction. See thakkarparth007's comment on:
# https://github.com/tomekwojcik/envelopes/issues/18
if type_maj == 'text' and type_min in ('html', 'plain'):
msg.attach(MIMEText(part[1], type_min, self._charset))
else:
msg.attach(part[1])
A simple (but maybe hackish) solution is to add another condition and make that if type_maj == 'text' and type_min in ('html', 'plain') and\
(isinstance(part[1], str) or isinstance(part[1], unicode)):
msg.attach(MIMEText(part[1], type_min, self._charset))
else:
msg.attach(part[1]) This will work (at least for now). |
I am trying to attach an HTML file to an email.
I get the following error:
Stepping into the code with ipython debugger it seems that it detects the MIME type of the file, correctly, as
text/html
but this causes it to follow a different codepath which is where it fails: https://github.com/tomekwojcik/envelopes/blob/master/envelopes/envelope.py#L292If I force it to use a generic mime type instead:
envelope.add_attachment("myfile.html", mimetype="application/octet-stream")
...then I can send the message but something weird happens - Gmail shows the message as having the file attached twice, even though if I go back and check the
envelope
object it seems I have only one attachment:The text was updated successfully, but these errors were encountered: