我有以下 vba 代码,它读取邮箱并向任何发送无效代码作为邮箱回复的用户发送回复,但有时会收到运行时错误(Outlook 无法识别一个或多个名称)。我的问题是,
- 创建新的 MAPI 配置文件是否可以解决该问题,或者我是否需要添加一个代码来解析地址并忽略电子邮件 ID 是否不再存在。如果是的话我该怎么做?
- 另外,一般来说,在特定条件下不发送电子邮件的参数是什么?
以下是我们目前拥有的代码:
Sub ResponseCodeError(Item As Outlook.MailItem)
'If not a valid code then send email to the User
If (Left(Item.Subject, 2) <> "S;" And Left(Item.Subject, 2) <> "N;") Then
Dim outobj, mailobj
Set outobj = CreateObject("Outlook.Application")
Set mailobj = outobj.CreateItem(0)
With mailobj
.To = Item.SenderEmailAddress
.Subject = "Invalid Code"
.Body = "Please use a valid CODE"
.Send
End With
'Move Email to Error Folder
mailboxNameString = "mailboxname"
FolderName = "Error"
Dim olApp As New Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Dim olCurrExplorer As Outlook.Explorer
Dim olCurrSelection As Outlook.Selection
Dim olDestFolder As Outlook.MAPIFolder
Set olNameSpace = olApp.GetNamespace("MAPI")
Set olCurrExplorer = olApp.ActiveExplorer
Set olCurrSelection = olCurrExplorer.Selection
Set olDestFolder = olNameSpace.Folders(mailboxNameString).Folders(FolderName)
Item.Move olDestFolder
End If
Set outobj = Nothing
Set mailobj = Nothing
End Sub
我曾经遇到过同样的错误,我在代码中疯狂搜索了 5 个小时后解决了它。但情况要简单得多:1 个电子邮件地址出现错误,缺少域名中的 .(点)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)