{"title":"import os\n\nsubtables_path = r"C:\Users\LOH2HZ\Desktop\2023.6 email sending\SubTables" # 定义子表文件夹的路径\n\n# 遍历 Excel 文件的每一行并附加相应的子表\nfor i, row in df.iterrows(): \n pm_name = row['Project manager']\n pm_email = row['Email address']\n cc = row['CC']\n \n if pd.isna(pm_name) or pd.isna(pm_email):\n print(f'Missing information for row {i}')\n continue\n\n msg = MIMEMultipart() \n msg['Subject'] = 'Open ProNovia E-mail reminder'\n msg['From'] = sender\n msg['To'] = pm_email\n msg['Cc'] = cc\n\n receiver_list = [pm_email]\n if not pd.isna(cc): \n receiver_list.extend(cc.split(',')) # Add cc values to the receiver_list if it is not empty\n\n \n content='''\n Dear PJMs & VS managers,
\n
\n This is a warm E-mail reminder about open ProNovia process of new components in your project.
\n
      · You can check your ProNovia status and push relevant associates to fast release components.
\n       (LINK:How to check components are stuck in which department)
\n
      · You can issue a CR to discontinue components if they are not needed any more or project cancelled.
\n
\n Let's make our effort together to shorten the components release duration!
\n
Thanks.
\n
PT-BE/ETS1-Hz Team
\n '''\n\n puretext = MIMEText(content,'html','utf-8') # plain html\n msg.attach(puretext)\n\n excel_path = os.path.join(subtables_path, f"{pm_name}.xlsx")\n if os.path.exists(excel_path):\n xlsxpart = MIMEApplication(open(excel_path, 'rb').read())\n xlsxpart.add_header('Content-Disposition', 'attachment', filename=f'{pm_name}.xlsx')\n msg.attach(xlsxpart)\n smtpObj.sendmail(sender, pm_email, msg.as_string()) # 发送邮件给该Project manager\n else:\n print(f'Subtable for {pm_name} not found')\n\n\nsmtpObj.quit() # 发送完所有的邮件后关闭连接\n\n为什么CC的邮箱没有收到邮件?内容:在发送邮件的代码中,将CC邮箱地址添加到了receiver_list列表中,但在实际发送邮件的部分,只使用了pm_email作为收件人。因此,CC的邮箱没有收到邮件。为了解决这个问题,需要修改代码,将receiver_list中的所有邮箱地址都添加到msg['Cc']中。修改的代码如下:\n\npython\nmsg['Cc'] = ",".join(receiver_list) # 将所有的收件人邮箱地址添加到Cc字段中\n\nsmtpObj.sendmail(sender, ",".join(receiver_list), msg.as_string()) # 发送邮件给所有收件人\n\n\n请注意,在这种情况下,邮件中的收件人将会看到所有人的邮箱地址。如果希望隐藏CC的邮箱地址,可以将receiver_list中的邮箱地址逐个添加到msg['Cc']中,并分别发送邮件给每个收件人。


原文地址: https://www.cveoy.top/t/topic/pq49 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录