vbscript - Outlook VBscript 方法 .Send 停止脚本
问题描述
我正在开发一个脚本来根据某些输入发送电子邮件,我能够制作电子邮件但不能使用该.Send
方法发送它。
我收到以下错误:(请注意,该行.Send
与原始案例中的使用相匹配)
我已经使用该.SendKeys(^~)
方法成功发送了电子邮件,但我想使用 Outlook 对象来执行此操作,而不仅仅是发送快捷方式。
这是我当前的代码:
' Declare all variables that will be used later on
Dim outobj, mailobj, emailto, cc, subject, body, attachement
Dim strFileText
Dim objFileToRead
Dim splitEmailto
' Set the outlook application object
Set outobj = CreateObject("Outlook.Application")
' set the namespace
Set myNamespace = outobj.GetNameSpace("MAPI")
msgbox myNamespace.Folders(2)
' Set the mail item object
Set mailobj = outobj.CreateItem(olMailItem)
' Set a shell
Set WshShell = WScript.CreateObject("WScript.shell")
' Get all the argument and assign
emailto = "name@domain.eu"
cc = "name@domain.eu"
subject = "Simple Email"
body = "Some Text"
attachement = "C:\Users\name\Desktop\fileName.xls"
' Craft the email object
With mailobj
.Display
' assign the tos
.To = cstr(emailto)
' add CCs
.CC = cstr(cc)
' attach the relevant files
If attachement <> "" Then
If instr(attachement, ";") Then
splitAtt = split(attachement, ";")
For Each att In splitAtt
If att <> "" Then
.Attachments.add cstr(att)
End If
Next
Else
.Attachments.add cstr(attachement)
End If
End If
If Subject <> "" Then
.Subject = Subject ' sets the subject
End If
If body <> "" Then
.Body = body ' sets the body
End If
.Send
End With
' Clear the memory
Set outobj = Nothing
Set mailobj = Nothing
' check for no more events in the sending event
' Report out & Quits
WScript.StdOut.WriteLine("Email sent")
WScript.Quit
我希望能够发送带有.Send
. 任何想法?
解决方案
错误是E_ABORT
。为什么显示消息并立即调用发送?您要么显示消息(显示,但不发送),要么只发送消息而不显示(发送,但不显示)。
推荐阅读
- python - 将多列从 String 转换为 Float 和 Int
- node.js - 在 Mongoose 中更新嵌套对象
- javascript - Joi:根据其他键的值过滤值
- excel - VBA代码从工作表上的下拉菜单中选择值并转到与同一工作表上的标题具有相同值的列 - Excel 2010
- react-native - React Native:在特定的深度链接 URL 处打开推送通知
- angular - RxJS 的 Observables 数组,带有要保存的额外数据
- r - 取消嵌套不同大小的相关列表列
- python - 检测列表中的连续整数 [Python 3]
- svg - 如何将svg图片显示为光标
- api - TypeORM - 获取提供的 id 的对象,这是一个关系