美好的一天
我需要帮助。
我无法发送带有附件的消息。
这是相关资源:
def send_email_with_mailgun(sender, recipients, subject, body, mail_gun_url, mailgun_api_key):
recipients = recipients if type(recipients) is list else [recipients]
try:
return requests.post(
mail_gun_url,
auth=("api", mailgun_api_key),
data={"from": sender,
"to": recipients,
"subject": subject,
"text": body},
files=[("attachment", (open("xxxxxxx.pdf", "rb")))],)
except:
pass
如果我删除它确实发送的参数,否则它不会发送
最佳答案
The docs建议你应该有一个文件名,像这样?
请求.post(
邮件枪网址,
auth=("api", mailgun_api_key),
数据={“来自”:发件人,
“致”:收件人,
“主题”:主题,
“文本”:正文},
files=[("附件", ("xxxxxxx.pdf", open("xxxxxxx.pdf", "rb").read()))],)
关于Python 如何使用mailgun发送附件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48633475/