Moving email attachment into inbox...

  • Thread starter Thread starter Bennett
  • Start date Start date
B

Bennett

I have a minor issue which is annoying. I have set up my work email to
forward to my Gmail account which I can access via POP in Outlook 2007. My
emails are sent as attachments and I can't change this.

I have Vista Sideshow set up to view my Outlook emails but it won't display
any attachments.

I can manually move (literally click and drag) the email attachment from the
email to my inbox in Outlook and it appears as a separate email (woohoo!).
Great. But the whole point is not to have to do this manually. About half
my emails are from this account, and most of the important ones are, so this
would be nice to fix.

I've tried writing a VBA macro to do this, but it insists on treating the
email attachment as an attachment, which in fact it's really a MailItem. The
software is clearly capable of dragging .msg files into the Outlook Inbox.
But how on earth do I tell Outlook to do that using VBA..? I kind of want to
"save" the "attachment" but specifically save it into the Outlook Inbox, NOT
a directory on the HDD.

Any ideas?
 
In general to work with any attachment you must save it to the file system
first. However, importing a MSG file from the file system or dealing with it
in any other way in code is not exposed in the Outlook object model. There's
a 3rd party library, Redemption (www.dimastr.com/redemption), that does let
you open and import MSG files into Outlook using code.
 
Thanks, I did find a way to do it.

Public Sub RemoveAttachments2(item As MailItem)

Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim Atmt As Attachment
Dim FileName As String
Dim itemnew As Object
Dim foundemail As Boolean
foundemail = False

Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)

For Each Atmt In item.Attachments

If Right(Atmt.FileName, 3) = "msg" Then ' checks for true email
attachments
foundemail = True
FileName = "c:\temp\"

Atmt.SaveAsFile FileName & Atmt.FileName

Set itemnew = Outlook.Application.CreateItemFromTemplate(FileName &
Atmt.FileName, Inbox)
itemnew.Save ' otherwise it saves a copy into OutBox...
itemnew.Move Inbox
itemnew.UnRead = True ' this doesn't work yet, not sure why
End If

Next Atmt

item.Move ns.GetDefaultFolder(olFolderDeletedItems) ' I can do this
because it only acts on postmaster emails!
End Sub

It's a little around the houses, but it works :o) As you said, it required
me to save the file to the HDD first, which in itself wasn't as much as
problem as it not apparently being reopened as an email item. (Using
CreateItemFromTemplate did the trick).

Cheers

Bennett
 
Hi Ken,
I am having the same problem. I have downloaded and installed
Redemption, but I still can't seem to get this to work. Do you have idea
where my code is wrong? Thanks!

Public Sub CopyAttachment(myMailItem As Outlook.MailItem)

Dim NS As Outlook.NameSpace
Dim olkFolderset As Outlook.Folders
Dim olkFolder As Outlook.Folder
Dim olkAttachedMSG, olkMailItem, olkNewMailItem As Outlook.MailItem
Dim redAttachment, redMailItem As Object
Dim strID As String

strID = myMailItem.EntryID
Set NS = Outlook.GetNamespace("MAPI")
Set olkFolder = NS.OpenSharedFolder("ITCS (POP)\Inbox")
Set olkMailItem = NS.GetItemFromID(strID)
Set redMailItem = CreateObject("Redemption.SafeMailItem")
redMailItem.item = olkMailItem
Set redAttachment = redMailItem.Attachment
Set olkAttachedMSG = redAttachment.EmbeddedMsg
Set olkNewMailItem = Outlook.CreateItem(olMailItem)
olkAttachedMSG.CopyTo (olkNewMailItem)
olkNewMailItem.Save
olkNewMailItem.Move (olkFolder)

End Sub
 
You still need to save the attachment to the file system no matter what. Use
SaveAs to save the file as a MSG file and then you can use
RDOSession.CreateMessageFromMsgFile to create an RDOMail item from the saved
MSG file, assuming it is actually an Outlook object saved as a MSG file.
 
Back
Top