import\u0020os\nfrom\u0020imapclient\u0020import\u0020IMAPClient\n\nsubtables_path\u0020=\u0020r"C:\Users\LOH2HZ\Desktop\2023.6\u0020email\u0020sending\SubTables"\u0020#\u0020定义子表文件夹的路径\n\n#\u0020遍历\u0020Excel\u0020文件的每一行并附加相应的子表\nfor\u0020i,\u0020row\u0020in\u0020df.iterrows():\u0020\n\u0020pm_name\u0020=\u0020row['Project\u0020manager']\n\u0020pm_email\u0020=\u0020row['Email\u0020address']\n\u0020\n\u0020if\u0020pd.isna(pm_name)\u0020or\u0020pd.isna(pm_email):\n\u0020\u0020\u0020print(f'Missing\u0020information\u0020for\u0020row\u0020{i}')\n\u0020\u0020\u0020continue\n\n\u0020msg\u0020=\u0020MIMEMultipart()\u0020#\u0020清空上一个邮件的附件\n\u0020msg['Subject']\u0020=\u0020'Open\u0020ProNovia\u0020E-mail\u0020reminder'\n\u0020msg['From']\u0020=\u0020sender\n\u0020msg['To']\u0020=\u0020pm_email\n\n\u0020content='''\n\u0020Dear\u0020PJMs\u0020&\u0020VS\u0020managers,
\n\u0020
\n\u0020This\u0020is\u0020a\u0020warm\u0020E-mail\u0020reminder\u0020about\u0020open\u0020ProNovia\u0020process\u0020of\u0020new\u0020components\u0020in\u0020your\u0020project.
\n\u0020
      · You\u0020can\u0020check\u0020your\u0020ProNovia\u0020status\u0020and\u0020push\u0020relevant\u0020associates\u0020to\u0020fast\u0020release\u0020components.
\n\u0020      (LINK:<a\u0020href="file://bosch.com/DfsRB/DfsCN/LOC/Hz/PTCN/Engineering/PT-BE-ETS-HZ_Act/EIS_Report/Pronovia/Reference/How%20to%20check%20components%20are%20stuck%20in%20which%20department.pdf">How\u0020to\u0020check\u0020components\u0020are\u0020stuck\u0020in\u0020which\u0020department)
\n\u0020
      · You\u0020can\u0020issue\u0020a\u0020CR\u0020to\u0020discontinue\u0020components\u0020if\u0020they\u0020are\u0020not\u0020needed\u0020any\u0020more\u0020or\u0020project\u0020cancelled.
\n\u0020
\n\u0020Let's\u0020make\u0020our\u0020effort\u0020together\u0020to\u0020shorten\u0020the\u0020components\u0020release\u0020duration!
\n\u0020
Thanks.
\n\u0020
PT-BE/ETS1-Hz\u0020Team
\n '''\n\n\u0020puretext\u0020=\u0020MIMEText(content,'html','utf-8')\u0020#\u0020plain\u0020html\n\u0020msg.attach(puretext)\n\n\u0020excel_path\u0020=\u0020os.path.join(subtables_path,\u0020f"{pm_name}.xlsx")\n\u0020if\u0020os.path.exists(excel_path):\n\u0020\u0020xlsxpart\u0020=\u0020MIMEApplication(open(excel_path,\u0020'rb').read())\n\u0020\u0020xlsxpart.add_header('Content-Disposition',\u0020'attachment',\u0020filename=f'{pm_name}.xlsx')\n\u0020\u0020msg.attach(xlsxpart)\n\u0020\u0020smtpObj.sendmail(sender,\u0020pm_email,\u0020msg.as_string())\u0020#\u0020发送邮件给该Project\u0020manager\n\u0020else:\n\u0020\u0020print(f'Subtable\u0020for\u0020{pm_name}\u0020not\u0020found')\n\n\nsmtpObj.quit()\u0020#\u0020发送完所有的邮件后关闭连接\n\n\n#\u0020保存邮件到已发送文件夹\nimap_server\u0020=\u0020'imap.example.com'\nimap_username\u0020=\u0020'your_username'\nimap_password\u0020=\u0020'your_password'\n\nwith\u0020IMAPClient(imap_server)\u0020as\u0020client:\n\u0020client.login(imap_username,\u0020imap_password)\n\u0020client.select_folder('Sent\u0020Items')\u0020#\u0020选择已发送文件夹\n\u0020client.append('Sent\u0020Items',\u0020msg.as_bytes())\u0020#\u0020将邮件保存到已发送文件夹中\n\n