diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index e8d209c..53b2d4b 100644
a
|
b
|
class EmailMessage(object):
|
309 | 309 | def attach_file(self, path, mimetype=None): |
310 | 310 | """Attaches a file from the filesystem.""" |
311 | 311 | filename = os.path.basename(path) |
312 | | with open(path, 'rb') as f: |
| 312 | if not mimetype: |
| 313 | mimetype, _ = mimetypes.guess_type(filename) |
| 314 | basetype, subtype = mimetype.split('/') |
| 315 | readmode = 'r' if basetype == 'text' else 'rb' |
| 316 | with open(path, readmode) as f: |
313 | 317 | content = f.read() |
314 | 318 | self.attach(filename, content, mimetype) |
315 | 319 | |