Python Email Sending with Excel Attachment - Troubleshooting CC Emails
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\nWhy are CC emails not being received? Possible reasons include:\n\n1. Incorrect CC Email Address: Check for typos or formatting errors in the 'CC' field.\n2. Invalid Email Address: Verify that the CC email address is a valid format (e.g., cc@example.com).\n3. Incorrect Assignment to msg['Cc']: Ensure the CC email is correctly assigned to the msg['Cc'] attribute. Print msg['Cc'] before sending to confirm.\n4. Multiple CC Addresses: If there are multiple CC recipients, separate them with commas or other appropriate delimiters.\n5. Blacklisting or Spam Filtering: Check if the CC address is blocked by spam filters or blacklists, preventing email delivery.\n\nIf these checks don't resolve the issue, try sending a separate email directly to the CC address to isolate the problem.
原文地址: https://www.cveoy.top/t/topic/pq6T 著作权归作者所有。请勿转载和采集!