louking / loutilities

some hopefully useful utilities
2 stars 2 forks source link

Add attachments to mail helper #98

Closed mrydz closed 1 year ago

mrydz commented 1 year ago

Add parameter to include attachments with emails. The additional parameter is a list of dicts containing the filename and file contents. File contents are passed instead of file path to give the flexibility to generate files in memory without disk.

Example call:

f = open("test2.json", "r")
varWithFileContents = '' # raw file contents

attach = []
attach.append({'filename': 'test.json, 'data': varWithFileContents })
attach.append({'filename': 'test2.json, 'data': f.read() })

sendmail('Test Subject', 'example@example.com', 'example@example.com', 'body', text='body', ccaddr=None, replytoaddr=None, attachments=attach):