kootenpv / yagmail

Send email in Python conveniently for gmail using yagmail
MIT License
2.64k stars 263 forks source link

Content-Type: None/None; name*=utf-8''filename.xlsx #196

Closed paradox-lab closed 3 years ago

paradox-lab commented 3 years ago

I attach xlsx files to emails that I send, but it cannot be displayed on the client.

expect : image

actual: image

I found the reason is that the value of Content-Type is None/None.

image

content_object["main_type"] get from mimetypes.guess_type, but it return None

In [1]: mimetypes.guess_type('/home/zhao.jz.2/aje/aje/download/webdriver/CaseInfo_20210324-Reports_summary.xlsx')
Out[1]: (None, None) 

when content_object["main_type"] is None and content_object["encoding"] == "base64", content_object["main_type"] and content_object["sub_type"] can't get any value.

yagmail/message.py line:206

if content_object["main_type"] is None or content_object["encoding"] is not None:
    if content_object["encoding"] != "base64":
        content_object["main_type"] = "application"
        content_object["sub_type"] = "octet-stream"

Finnally,the value of Content-Type is None/None.

How should I deal with this kind of problem?

paradox-lab commented 3 years ago

The problem has been solved.

On CentOS 7 it need to install a package named "mailcap":

yum install mailcap

execute script:

In [1]: mimetypes.guess_type('/home/zhao.jz.2/aje/aje/download/webdriver/CaseInfo_20210324-Reports_summary.xlsx')
Out[1]: ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', None)

then Content-Type become 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.