Электронная почта Python PDF из файлового каталога - PullRequest
0 голосов
/ 29 августа 2018

Мне нужно отправить электронное письмо в формате pdf и общее сопроводительное письмо из файлового каталога на адрес электронной почты, который соответствует 5-значному коду. код можно найти в первых 5 имени pdf, а затем в соответствующем кадре данных, который содержит 5-значный код и адрес электронной почты. Есть ли простой способ сделать это? Спасибо

 # loop through the email list 
for i in email_list.itertuples():
    PDF_name = i.AGCODE + '_2017 Net_Initial.pdf'
    cover_letter_name = 'CoverLetter.pdf' 
    print(PDF_name)
 #attach an excel file and PDF file: 
with open(dir_path + PDF_name, 'rb') as f, open(dir_path + cover_letter_name, 'rb') as g:
 # Read the binary file contents
     PDF_content = f.read()  
     cl_content = g.read()
     PDF_att = FileAttachment(name=PDF_name, content=PDF_content) 
     cl_att = FileAttachment(name=cover_letter_name, content=cl_content) 

 # if you want a copy in the 'Sent' folder
m = Message(
      account=a 
     ,folder=a.sent
     ,subject=('Award Letter for ' + i.FACILITY_NAME + ' -- Agency Code: ' + i.AGCODE)
     ,body = body_of_email 
     ,to_recipients=[Mailbox(email_address=i.FAC_EMAIL_ADDR)])

#attach files
m.attach(cl_att)
m.attach(PDF_att)
# send email each time          
m.send_and_save()
#======================== 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...