如何使用SES随附的CSV将数据框和sendmail上的CSV转换为CSV

发布于 2025-02-13 11:37:49 字数 895 浏览 1 评论 0原文

我必须使用包含数据框的CSV在代码末尾发送MENDMAIL。

我使用BOTO3在AWS Lambda上进行此操作,以打电话给SES。

def sendMail1(value, df):
   subject = "Comission"
   client = boto3.client("ses")
   body = f"""
             Comission value is {value}.
           """
message = {"Subject": {"Data": subject}, "Body": {"Html": {"Data": body}}}
attachment = df.to_csv(f"Comission.csv", index=False)
response = client.send_email(Source = "[email protected]", Destination = {"ToAddresses": ["[email protected]"]}, Message = message, Attachment = attachment)

我没有IDEIA如何做,我尝试了DF.TO_CSV方法,并将其包含在附件。没有工作。

其余的代码无需附件零件工作,但是我需要将DF附加到电子邮件。

你们知道该怎么做吗?

I have to sendmail at the end of my code with csv attached containing a dataframe.

Im doing it at AWS Lambda using boto3 to call SES as it follows.

def sendMail1(value, df):
   subject = "Comission"
   client = boto3.client("ses")
   body = f"""
             Comission value is {value}.
           """
message = {"Subject": {"Data": subject}, "Body": {"Html": {"Data": body}}}
attachment = df.to_csv(f"Comission.csv", index=False)
response = client.send_email(Source = "[email protected]", Destination = {"ToAddresses": ["[email protected]"]}, Message = message, Attachment = attachment)

I had no ideia how to do it, I tried df.to_csv method and include it as attachment. Did not work.

The rest of the code works without the attachment parts, but I need to attach my df to the e-mail.

Do you guys have any idea how to do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枉心 2025-02-20 11:37:49
df.to_csv(f"Comission.csv", index=False)

to_emails = [target_email1, target_email2]
ses = boto3.client('ses')
msg = MIMEMultipart()
msg['Subject'] = 'weekly report'

msg['From'] = from_email

msg['To'] = to_emails[0]


# what a recipient sees if they don't use an email reader
msg.preamble = 'Multipart message.\n'

# the message body
part = MIMEText('Howdy -- here is the data from last week.')
msg.attach(part)

# the attachment
part = MIMEApplication(open('Comission.csv', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename='Comission.csv')
msg.attach(part)

result = ses.send_raw_email(
             Source=msg['From'],
             Destinations=to_emails,
             RawMessage={'Data': msg.as_string()})                                                                                                       
# and send the message
print result
df.to_csv(f"Comission.csv", index=False)

to_emails = [target_email1, target_email2]
ses = boto3.client('ses')
msg = MIMEMultipart()
msg['Subject'] = 'weekly report'

msg['From'] = from_email

msg['To'] = to_emails[0]


# what a recipient sees if they don't use an email reader
msg.preamble = 'Multipart message.\n'

# the message body
part = MIMEText('Howdy -- here is the data from last week.')
msg.attach(part)

# the attachment
part = MIMEApplication(open('Comission.csv', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename='Comission.csv')
msg.attach(part)

result = ses.send_raw_email(
             Source=msg['From'],
             Destinations=to_emails,
             RawMessage={'Data': msg.as_string()})                                                                                                       
# and send the message
print result
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文