如何在VisualWorks Smalltalk中通过Outlook添加附件发送邮件?
Outlook邮件添加附件的正确方法
你之前直接用setProperty: #Attachments value: 'C:\temp\file.txt'不行,是因为Outlook的Attachments是集合对象,不是普通字符串属性,不能直接赋值,必须调用集合的Add方法来添加附件。
修改后的完整代码如下:
(t2 := (COMDispatchDriver createObject: 'Outlook.Application') invokeMethod: #CreateItem withArguments: #(0)) setProperty: #To value: 'x.x@abc.com'; setProperty: #CC value: ''; setProperty: #Subject value: 'Test'; setProperty: #Body value: 'Here comes the file'; "添加附件:先获取Attachments集合,再调用Add方法传入文件路径" getProperty: #Attachments; invokeMethod: #Add withArguments: #('C:\temp\file.txt'); invokeMethod: #Send withArguments: #(). session release.
关键说明:
- 先通过
getProperty: #Attachments获取邮件的附件集合对象 - 调用该集合的
Add方法,把文件路径作为参数传入(参数要放在数组里,符合invokeMethod:withArguments:的要求) - 这样就能正确将指定文件添加为邮件附件,之后再调用
Send发送即可
内容的提问来源于stack exchange,提问作者Guinness
相关产品推荐
相关产品推荐

