liiight/notifiers

No specification of attachment file types

Magnati opened this issue · 3 comments

Hello @liiight

This is kind of a feature request/second-layer-bug-but-not-realy-a-bug.

In notifiers/providers/email.py:120ff

@staticmethod
    def _add_attachments(data: dict, email: EmailMessage) -> EmailMessage:
        for attachment in data["attachments"]:
            file = Path(attachment).read_bytes()
            part = MIMEApplication(file)
            part.add_header("Content-Disposition", "attachment", filename=attachment)
            email.attach(part)
return email

... the header of the MIME application is set to the most generic type for attachments.
For all thunderbird users this creates the issue, that the attachments are not shown, since thunderbirds has a long time bug of not showing the attachments if the file type is not further specified.

So this is a request to either

  • make it possible to define the file-type over parameter,
  • or implement a file-type detection in Notifiers itself.

Greetings,
Magnati

hi @Magnati, can you provide more context for this? perhaps an example with a specific file-type?

Sorry for the late response.

The file type for which it occurred for me is .zip.
Thunderbird: 60.6.1 (64-Bit)
Python: 3.7.1
notifier: 1.0.4

Below a minimal example which reproduced the behaviour in my case.

import os

import notifiers
import pathlib

def send_zip(directory, mail):

    p = notifiers.get_notifier("email")

    # server credentials
    user = "<your user>"
    pw = "<your password>"
    port = 12345
    host = "<your host>"

    status = p.notify(
        to=mail,
        username=user,
        password=pw,
        message="Test sending.",
        subject="Test sending.",
        ssl=True,
        port=port,
        html=host,
        host="smtp.ambrosys.de",
        attachments=[directory],
    )
    print(status)


if __name__ == "__main__":
    mail = "yourl@mail.com"
    directory = "/your/file/path.zip"
    send_zip(directory, mail)

I actually fixed this in #267.

If you'd like sending an email to python.notifiers@gmail.com I'd send you a test email back