[英]Python Email Send to Multiple Recipients
My code doesn't have a problem. 我的代码没有问题。 In my list of recipients, I have 10 emails adress.
在我的收件人列表中,我有10封电子邮件地址。 Do you know to send an email to every singles address email of this list?
您知道要向此列表的每个单身电子邮件发送电子邮件吗?
Message error: 讯息错误:
pywintypes.com_error: (-2147352567, 'Exception occurred.', (4096, 'Microsoft Out look', 'Outlook does not recognize one or more names. ', None, 0, -2147467259), None) 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()
I would make a function to send a message, and then just put a for loop that says for email in email_list: send_email(your_subject, your_message, email)
我将创建一个发送消息的功能,然后在
for email in email_list: send_email(your_subject, your_message, email)
放入一个for循环,该循环表示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()
this is my function for sending e_mail through yahoo, but it can be adapted by logging into the appropriate smtp server for your provider (I would guess outlook from your code) 这是我通过yahoo发送电子邮件的功能,但可以通过为您的提供商登录相应的smtp服务器进行修改(我想您的代码中会提供Outlook)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.