我不知道如何在发送邮件时添加文件作为附件。 我尝试过:
t2 setProperty: #Attachments value: 'C:\temp\file.txt'.
该属性似乎是正确的,因为它不会抛出错误。但没有附加任何文件。我怀疑这是因为我尝试发送一个字符串...
这就是我所拥有的并且有效。
(t2 := (COMDispatchDriver createObject: 'Outlook.Application') invokeMethod: #CreateItem withArguments: #(0)) setProperty: #To value: '[email protected]'.
t2 setProperty: #CC value: ''.
t2 setProperty: #Subject value: 'Test'.
t2 setProperty: #Body value: 'Here comes the file'.
t2 invokeMethod: #Send withArguments: #().
session release.
谁能告诉我如何添加附件?
您必须将文件内容附加到图形 API 调用。我用的就是这个...
buildAttachmentFilename: aFilename
| content |
content := aFilename asFilename contentsOfEntireFile asByteArray asBase64String.
^Dictionary
with: '@odata.type' -> '#microsoft.graph.fileAttachment'
with: 'name' -> aFilename asFilename filename
with: 'contentType' -> (self getAttachmentContentType: aFilename)
with: 'contentBytes' -> content.
...然后将每个文件与“主题”、“正文”、“收件人”等一起添加为“附件”值中的条目。 由于我们记录电子邮件发送,因此我使用草稿 + 消息发送序列,因此附件是请求内容的字典的一部分。
draftOutlookMessageJson: aDictionary
| httpClient request |
httpClient := Net.HttpClient new.
request := Net.HttpRequest method: 'POST' url: 'https://graph.microsoft.com/v1.0/me/messages'.
request contents: aDictionary asJson.
request contentType: 'application/json'.
request authorization: 'Bearer ' , self graphAccessToken.
(request getFieldAt: 'Prefer') value: 'IdType="ImmutableId"'.
^httpClient executeRequest: request
fwiw:我们的应用程序部署在使用 ZnClient 的 GemStone 上。此 VW 代码方便开发。
根据文档:Microsoft,属性
Attachments
的类型为Attachments
而不是String
,因此您不能将其设置为String
。它也是事物的集合,而不仅仅是单一事物。
因此,您应该尝试将
Add
发送到 Attachments
对象,如下所示:
(t2 getProperty: #Attachments) invokeMethod: #Add withArguments: #('C:\temp\file.txt')
(我没有测试过代码)