我正在使用 python 2.7 和 boto3。
我无法找到在 python 中向 SES 添加附件的方法。
我发现的最接近的东西是这一页 https://gist.github.com/yosemitebandit/2883593.
到目前为止我所拥有的是这样的:
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
import boto3
# via http://codeadict.wordpress.com/2010/02/11/send-e-mails-with-attachment-in-python/
ses = boto3.client('ses')
msg = MIMEMultipart()
msg['Subject'] = 'weekly report'
msg['From'] = email
msg['To'] = other_email
# 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('cat.jpg', 'rb').read())
part.add_header('Content-Disposition', 'attachment', filename='cat.jpg')
msg.attach(part)
result = ses.send_raw_email(
Source=msg['From'],
Destinations=msg['To'],
RawMessage=msg
)
# and send the message
print result
我得到:
ParamValidationError: Parameter validation failed:
Invalid type for parameter RawMessage, value: From nobody Tue Jul 25 11:21:41 2017
Content-Type: multipart/mixed; boundary="===============0285276385=="
MIME-Version: 1.0
Subject: weekly report
From: email
To: other_email
“email”和“other_email”经过审查,但采用字符串格式'[电子邮件受保护] /cdn-cgi/l/email-protection'。
地址通过AWS授权,Key和Secret密钥已经通过boto3实现。
还在输出的底部得到了这个:
type: <type 'instance'>, valid types: <type 'dict'>
Invalid type for parameter Destinations,
value: other_email,
type: <type 'str'>, valid types: <type 'list'>, <type 'tuple'>