保存附件后如何删除电子邮件

时间:2019-05-14 14:58:55

标签: vb.net email outlook

我有此代码,正在工作 我希望能够删除保存了附件的特定电子邮件,但似乎无法弄清楚。 感谢所有帮助 谢谢

Public Function SaveAttachments(ByVal sPathName As String) As Boolean

    Dim oOutlook As Outlook.Application
    Dim oNs As Outlook.NameSpace
    Dim oFldr As Outlook.MAPIFolder
    Dim oMessage As Object
    Dim iCtr As Integer
    Dim iAttachCnt As Integer
    Dim sFileName As String
    Dim newMail As Outlook.MailItem = Nothing
    Try
        oOutlook = New Outlook.Application
        oNs = oOutlook.GetNamespace("MAPI")
        oFldr = oNs.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Folders("Granville_Auto")
        For Each oMessage In oFldr.Items
            With oMessage.Attachments
                iAttachCnt = .Count
                If iAttachCnt > 0 Then
                    For iCtr = 1 To iAttachCnt
                        Try
                            sFileName = .Item(iCtr).FileName.ToString
                            stdProcessorUpdates.txt1.Text = sFileName
                            Application.DoEvents()
                            'XX = MyLookUp("Select FileName From tblGranvilleImPorts where FileName = '" & sFileName)
                            'If Len(XX) < 5 Then
                            .Item(iCtr).SaveAsFile(sPathName & sFileName)

  THIS IS WHERE I WANT TO DELETE EMAIL

                     'newMail.Delete()
                            'End If

                        Catch ex As Exception
    End Try
                    Next iCtr
                End If
            End With
            Application.DoEvents()

        Next oMessage

我知道我已经很近了,但是缺少一些东西

0 个答案:

没有答案