I followed example at python.org library but get error "'pngfiles' is not defined". How do I define pngfiles variable? Is this a directory where .png files are? I thought the script should attach all .png files in the directory? This is my code. SMTP server is working with PS apps I wrote.
import smtplib
from email.message import EmailMessage
msg = EmailMessage()
msg['Subject'] = 'Our family reunion'
me = ('[email protected]')
family = ('[email protected]', '[email protected]')
msg['From'] = me
msg['To'] = ', '.join(family)
msg.preamble = 'You will not see this in a MIME-aware mail reader.\n'
for file in pngfiles:
with open(file, 'rb') as fp:
img_data = fp.read()
msg.add_attachment(img_data, maintype='image',
subtype='png')
with smtplib.SMTP('mail.mycompany.local') as s:
s.send_message(msg)