首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Outlook回复,然后删除邮件项

Outlook回复,然后删除邮件项
EN

Stack Overflow用户
提问于 2016-06-18 13:32:22
回答 1查看 498关注 0票数 2

这段代码有点粗糙,但它只是一个模拟。它的基本工作是:

当电子邮件从我的电子邮件中收到时,主题行以“批处理”开头:

  • 将电子邮件复制到另一个文件夹
  • 回复电子邮件
  • 删除原始电子邮件

现在是做我想做的一切,除了删除最后的电子邮件。在我回复邮件后,似乎无法找到原始的电子邮件对象来删除它。我知道事情会很简单,但我看不见.

代码语言:javascript
复制
Sub Check_For_Ticket(MyMail As MailItem)
Dim mysubject As String
Dim strEmail As String

'On Error GoTo Ticketerror

myemail = "pb***********@hotmail.com"
mysubject = "Batch*"

strEmail = MyMail.SenderEmailAddress
strSubject = MyMail.Subject
If strEmail = myemail And strSubject Like mysubject Then
    MsgBox "yes" & strSubject
    Call pbMoveMessageToTestFolder(MyMail)
    Call AutoReply(MyMail)
Else
    MsgBox "no" & strSubject
End If

MsgBox "this email is: " & strSubject
'Ticketerror:
'    MsgBox "There is an error "
'    MsgBox Err.Number & " : " & Err.Description
End Sub
Sub pbMoveMessageToTestFolder(MyMail As MailItem)

' Works on one selected item

    Dim myNameSpace As Outlook.NameSpace
    Dim myInbox As Outlook.Folder
    Dim myDestFolder As Outlook.Folder
    Dim myItem As Object
    Dim objcopy As Object

        MsgBox "into 2nd sub"

    Set myNameSpace = Application.GetNamespace("MAPI")
    Set myInbox = myNameSpace.GetDefaultFolder(olFolderInbox)

    ' Add As many  .Folders("SubfolderName")  as needed
    Set myDestFolder = myInbox.Folders("To_Process")
    Set myItem = MyMail
    'Application.ActiveExplorer.Selection.Item (1)

    Dim copy As Object
    Set copy = myItem.copy
    'move copy to folder
    copy.Move myDestFolder

        MsgBox "should of copied"

    Set myNameSpace = Nothing
    Set myInbox = Nothing
    Set myDestFolder = Nothing
    Set myItem = Nothing

End Sub
Sub AutoReply(olItem As Outlook.MailItem)
'declaring variables
Dim olOutMail As Outlook.MailItem
Dim olOutMail2 As Outlook.MailItem
Dim strpbsubject As String
Dim strSubject As String
Dim Str As String

Str = olItem.Subject

MsgBox "3rd sub - subject: " & Str

strpbsubject = "This is an auto-reply from ***, confirming that " & strMid & " has been successfully received at " & Format(DateTime.Now, "dd-MM-yyyy hh:mm:ss")


'Creating the reply email

    With olItem
        Set olOutMail2 = olItem.Reply
        With olOutMail2
            .Body = strpbsubject 'Placing the body of the email in place
            .Subject = "Delivered: " & Str 'appending "Delivered" to the subject line
            .Send        ' This is a changeable variable to display the reply change to .Display
                        ' to deliver the response change to .Send
            .UnRead = True 'makes the email unread after the  auto response is sent
        End With
    Set olOutMail2 = Nothing



    End With

End Sub
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-06-19 05:32:04

尝试在MyMail.Delete之后添加Call AutoReply(MyMail)

代码语言:javascript
复制
If strEmail = myEmail And mysubject Like mysubject Then
    MsgBox "yes" & mysubject
    Call pbMoveMessageToTestFolder(MyMail)
    Call AutoReply(MyMail)
    MyMail.Delete
Else
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37897551

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档