Outlook send selected email as attachment and delete

I'm looking for a way to automaticaly send email items in my inbox as an attachment to a fixed address. Also I 'd like to creat a button on my toolbar and tie this action to it.

Example: I select a few items in my inbox and then click the toolbar button. Those selected items are then inserted in to a new email. That new email is sent to a somthing@somthing.com. After the email is sent, the selected emails are deleted.

I'm using Outlook 2010
Erik CurtisEnterprise ArchitectAsked:
Who is Participating?
copy code below into a macro

This page will show you how to add a button to the toolbar


Private Declare Function GetTempPath Lib "kernel32" _
         Alias "GetTempPathA" (ByVal nBufferLength As Long, _
         ByVal lpBuffer As String) As Long
      Private Declare Function GetTempFileName Lib "kernel32" _
         Alias "GetTempFileNameA" (ByVal lpszPath As String, _
         ByVal lpPrefixString As String, ByVal wUnique As Long, _
         ByVal lpTempFileName As String) As Long
      Private Function CreateTempFile(sPrefix As String) As String
         Dim sTmpPath As String * 512
         Dim sTmpName As String * 576
         Dim nRet As Long
         nRet = GetTempPath(512, sTmpPath)
         If (nRet > 0 And nRet < 512) Then
            nRet = GetTempFileName(sTmpPath, sPrefix, 0, sTmpName)
            If nRet <> 0 Then
               CreateTempFile = Left$(sTmpName, _
                  InStr(sTmpName, vbNullChar) - 1)
            End If
         End If
      End Function
Sub GetSelected()
Dim messages()
Dim mail As MailItem
Dim tmpPath
Dim currentMail As MailItem
If Not IsEmpty(ActiveExplorer.Selection) Then
    For Each CurrentItem In ActiveExplorer.Selection
        If CurrentItem.Class = olMail Then
            If mail Is Nothing Then Set mail = Application.CreateItem(olMailItem)
                counter = counter + 1
                Set currentMail = CurrentItem
                tmpPath = CreateTempFile("OL")
                currentMail.SaveAs tmpPath, olMSG
                mail.Attachments.Add tmpPath
            End If
End If
mail.BodyFormat = olFormatHTML
mail.Subject = "Emails forwarded"
mail.Body = "emails attached"
mail.To = "yourEmail@ou.com"
msgbox "Finished"
end sub

Open in new window

Naser GabajE&P Senior Software SpecialistCommented:

I never try it before, but I believe this tool can do the job for you


Good luck
Erik CurtisEnterprise ArchitectAuthor Commented:
This works just as it should!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.