我的代码没有问题。在我的收件人列表中,我有10封电子邮件地址。 您知道要向此列表的每个单身电子邮件发送电子邮件吗?
消息错误:
pywintypes.com_error:(-2147352567,'发生异常。',(4096,'Microsoft Out 外观”,“ Outlook无法识别一个或多个名称。 ',无,0,-2147467259), 没有)
import win32com.client as win32
import pandas as pd
xls = pd.ExcelFile(path)
dfs = xls.parse(sheet_name="details", header = None)
recipients = dfs[21]
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = recipients
mail.Subject = 'Automatic Email '
mail.Body = 'body'
mail.HTMLBody = 'Hello, this is a test </h2>'
mail.Send()
答案 0 :(得分:0)
我将创建一个函数来发送消息,然后仅放置一个表示for email in email_list: send_email(your_subject, your_message, email)
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def send_email(subject, message, recipient):
smtp_obj = smtplib.SMTP('smtp.mail.yahoo.com', 587)
smtp_obj.starttls()
smtp_obj.ehlo()
smtp_obj.login('your_username_here', 'your_password_here')
msg = MIMEMultipart()
msg['From'] = 'your_email_here'
msg['To'] = recipient
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
smtp_obj.sendmail(msg['From'], msg['To'], msg.as_string())
smtp_obj.quit()
这是我通过yahoo发送电子邮件的功能,但可以通过登录到适用于您的提供商的适当smtp服务器进行修改(我想您的代码中会提供Outlook)