yagmail icon indicating copy to clipboard operation
yagmail copied to clipboard

How to send html file as attachment?

Open smjure opened this issue 5 years ago • 1 comments

First of all thank you for the great app.

I have to send .html reports automatically. Idea is to send it as either attachment or inline. I tried several things:

yag=yagmail.SMTP('[email protected]','PASS')
contents = ["//path/to/file.html"]
yag.send('[email protected]', f'Subject',contents)

and

yag.send('[email protected]', f'Subject',yagmail.inline("//path/to/file.html"))

and

yag.send('[email protected]', f'Subject',yagmail.raw("//path/to/file.html")) 

If I sent it as html attachment or inline, this is the result where I cannot see the html content. Selection_402

If I change ".html" file name, to e.g. ".tt", the file is successfully attached. So, how can I attache a .html file without renaming it?

smjure avatar Jun 01 '20 11:06 smjure

If you want to send it as inline, just write the HTML code directly in contents. contents = "<h1>This is a big title!</h1>"

If you want to attach HTML files inline, write a function to extract the code from it and pass it to contents as a string.

MLpranav avatar Jul 24 '20 16:07 MLpranav