0

我正在使用 REST API 调用来触发来自我的应用程序的邮件。请求如下

https://dm.aliyuncs.com/?Action=SingleSendMail
&AccountName=test@example.com
&ReplyToAddress=true
&AddressType=1   
&ToAddress=test1@example.com
&Subject=Subject
&HtmlBody=body
&<Public request parameter>

我从示例中假设它是一个 GET 调用,如何将附件与请求一起上传?

4

2 回答 2

0

我看到这是一个 GET 调用。我假设您指的是以下链接

https://www.alibabacloud.com/help/doc-detail/29444.htm

我认为您不能使用此 REST 接口上传附件。另一种选择是创建第三方 API,该 API 反过来会使用 SDK(JAVA/Node)来促进附件添加。

于 2018-07-28T09:29:46.953 回答
0

电子邮件附件是电子邮件正文的一部分。

大多数人使用 MIME 编码库来处理他们的电子邮件正文以包含附件。这也意味着您必须使用 HTML 邮件。

注意:由于您使用的是REST API,所以我写了一篇关于如何使用阿里巴巴DirectMail REST API和Python中的实际工作代码的文章:DirectMail REST API

以下是带有附件的电子邮件的示例:

From: John Doe <example@example.com>
MIME-Version: 1.0
Content-Type: multipart/mixed;
        boundary="XXXXboundary text"

This is a multipart message in MIME format.

--XXXXboundary text 
Content-Type: text/plain

this is the body text

--XXXXboundary text 
Content-Type: text/plain;
Content-Disposition: attachment;
        filename="test.txt"

this is the attachment text

--XXXXboundary text--

这是电子邮件附件的示例 Python 代码:Python 示例

# Import smtplib for the actual sending function
import smtplib

# Here are the email package modules we'll need
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart

COMMASPACE = ', '

# Create the container (outer) email message.
msg = MIMEMultipart()
msg['Subject'] = 'Our family reunion'
# me == the sender's email address
# family = the list of all recipients' email addresses
msg['From'] = me
msg['To'] = COMMASPACE.join(family)
msg.preamble = 'Our family reunion'

# Assume we know that the image files are all in PNG format
for file in pngfiles:
    # Open the files in binary mode.  Let the MIMEImage class automatically
    # guess the specific image type.
    fp = open(file, 'rb')
    img = MIMEImage(fp.read())
    fp.close()
    msg.attach(img)

# Send the email via our own SMTP server.
s = smtplib.SMTP('localhost')
s.sendmail(me, family, msg.as_string())
s.quit()
于 2018-07-28T16:50:42.867 回答