• How to copy an attachment

    Author
    Topic
    #353477

    This one has me stumped. I’m trying to use VB scripting within Outlook 2000 to programmatically take an e-mail message and copy all of its contents to a new message. Everything is working except for copying attachments. I can tell how many attachments are in the original, and determine all the information about each attachment. But I cannot find the correct code to copy the attachments to the new piece of e-mail. Before you ask, no, this is not for an e-mail virus!

    Viewing 2 reply threads
    Author
    Replies
    • #517280

      Looks as though you may need to use the Attachment.SaveAs method, to store the attachments in some temporary location. To retrieve the path to the user’s temp folder:

      (1) Set a reference to the Microsoft Scripting Runtime

      (2) Use the GetSpecialFolder method:

      Dim objFS As New Scripting.FileSystemObject, strTempPath As String
      strTempPath = objFS.GetSpecialFolder(TemporaryFolder)

      That should be a reasonably safe place to drop the files, but you could always give them a unique name as well.

    • #517315

      see slipstick for the VB code needed.

    • #517374

      Hello Briana,

      I know you want to program it, but will a simple Forward not doing it all for you?

      • #518110

        I want to thank everyone for the assistance. Since I couldn’t do a simple forward,(which I tried first, by the way), it was beginning to be a bit of a problem. Here’s my solution:

        Private Sub Copy_Attachments(FromMail As MailItem, ToMail As MailItem)
        Dim i As Integer
        Dim SavedName As String

        For i = 1 To FromMail.Attachments.Count
        With FromMail
        If FromMail.Attachments.Count > 0 Then
        SavedName = “C:” & FromMail.Attachments.Item(i).FileName
        FromMail.Attachments.Item(i).SaveAsFile SavedName
        ToMail.Attachments.Add SavedName
        Kill SavedName
        End If
        End With
        Next
        End Sub

        Again, thanks!

        • #518125

          were you wanting to forward as attachment but had it set to forward inline? you can change the option is tools > option. also, if you select multiple messages and choose forward they go as attachment, just delete theextra ones.

          • #518133

            What I am doing is writing an Outlook-driven PDL that requires no signup. When a message comes in, my PDL application finds the manager(s) that the message is from, then looks up their entire reporting structure in the corporate database and builds a BCC list. It then sends a copy of the message out to everyone on the list. I tried the FORWARD function, but for some reason, I kept getting an error from my Exchange server about permissions. I fixed that by making a copy of the message and sending the copy, rather than the original.

            The attachments was the last major hurdle. Aside from testing, it seems to be ready for release.

    Viewing 2 reply threads
    Reply To: How to copy an attachment

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: