dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: deleting Outlook attachments

  1. #1
    Join Date
    Aug 2001
    Posts
    1,447

    deleting Outlook attachments

    My VB code for saving attachments to a file and then deleting them from the email saved the file just fine and SEEMED to do the delete as well (I got no error, or any message saying the delete didn't work) BUT the attachment did not go away. I moved the code into VBA inside Outlook, thinking that there was a security setting that prevented external code from doing a delete. My security setting is "LOW" (as low as it can be set). The code had exactly the same effect inside Outlook as outside --- the attachment saves as a file just fine but the delete method, despite giving no indication that it isn't doing anything, doesn't do any thing.

    Help !

    Thanks,

    Paul
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: deleting Outlook attachments

    How can we help if you don't help yourself?

    We can't see your code, so if you want us to help, post it.

    Code:
    ' Use Code Tags
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Aug 2001
    Posts
    1,447

    Re: deleting Outlook attachments

    good point, although I suspect that the problem is somehow with the security setting, not the code.

    Here's the code

    Private Sub sub2()
    Dim oApp As Outlook.Application
    Dim oNameSpace As NameSpace
    Dim oFolder As MAPIFolder
    Dim oMailItem As MailItem
    Dim sMessage As String
    Dim n As Integer

    Set oApp = New Outlook.Application
    Set oNameSpace = oApp.GetNamespace("MAPI")
    Set oFolder = oNameSpace.PickFolder
    n = 0
    For Each oMailItem In oFolder.Items
    With oMailItem
    If oMailItem.Attachments.Count > 0 Then
    oMailItem.Attachments.Item(1).SaveAsFile "c:\temp\temp\" & Format(CStr(n), "00#") & _
    oMailItem.Attachments.Item(1).FileName
    If InStr(1, oMailItem.Attachments.Item(1).FileName, "2006 phinds") <> 0 Then
    oMailItem.Attachments.Item(1).Delete
    n = n + 1
    End If
    DoEvents
    End If
    End With
    Next oMailItem
    MsgBox "n = " & n
    Set oMailItem = Nothing
    Set oFolder = Nothing
    Set oNameSpace = Nothing
    Set oApp = Nothing
    End Sub
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: deleting Outlook attachments

    That could be. Does a macro work from within outlook?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Aug 2001
    Posts
    1,447

    Re: deleting Outlook attachments

    Don't quite see how I could test that since capturing the macro means deleting an attachment during the macro capture but then re-running the macro would be pointless since the attachment would already be gone.
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: deleting Outlook attachments

    edit the code in the VBA Editor. Record the macro to do one file, and then edit to do another.

    I think it's permissions that you'd need a certificate to get around
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Aug 2001
    Posts
    1,447

    Re: deleting Outlook attachments

    good idea on the macro thing ... I'll try that tomorrow.

    Any idea how to change permissions or get a certificate? I have the outlook security permissions set as low as they'll go, so what am I missing?

    Thanks,

    Paul
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  8. #8
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: deleting Outlook attachments

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  9. #9
    Join Date
    Aug 2001
    Posts
    1,447

    Re: deleting Outlook attachments

    Ah, I appreciate the suggestion, but this seems to apply only to IIS installations which I do not have, AND the documentation says only use this facility, and I quote, " When you have to create a security-enhanced private channel between your server and a limited, known group of users" --- seems to imply that it will screw up my email to other users, which I cannot afford.
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

  10. #10
    Join Date
    Aug 2001
    Posts
    1,447

    Re: deleting Outlook attachments

    >> Does a macro work from within outlook?

    OK, I tried the code as a macro but it acts exactly the same --- no surprize there since you can't RECORD macros in outlook so this is not a macro created by outlook, it's just a new name for the same code pasted into a macro name.

    Still, this all does seem to imply that there's a security problem, not a code problem.

    Any suggestions?

    Thanks,

    Paul
    phinds
    vs2008, 3.5SP1 Version 9.0.21022.8 RTM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)