WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Moving email attachment into inbox...

 
   Home -> Office -> Programming VBA RSS
Next:  Create a macro to open a MS access database  
Author Message
Bennett

External


Since: Apr 28, 2006
Posts: 2



(Msg. 1) Posted: Tue Oct 07, 2008 5:06 pm
Post subject: Moving email attachment into inbox...
Archived from groups: microsoft>public>outlook>program_vba (more info?)

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?
Back to top
Login to vote
Ken Slovak - [MVP - Outlo

External


Since: Oct 17, 2003
Posts: 2999



(Msg. 2) Posted: Wed Oct 08, 2008 9:21 am
Post subject: Re: Moving email attachment into inbox... [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Bennett" <Bennett DeleteThis @discussions.microsoft.com> wrote in message
news:F3A3AFE1-D8E9-4802-9AEC-BB038FD4A946@microsoft.com...
>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?
Back to top
Login to vote
Bennett

External


Since: Apr 28, 2006
Posts: 2



(Msg. 3) Posted: Wed Oct 08, 2008 4:58 pm
Post subject: Re: Moving email attachment into inbox... [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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 Surprised) 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


"Ken Slovak - [MVP - Outlook]" wrote:

> 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.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Bennett" <Bennett.TakeThisOut@discussions.microsoft.com> wrote in message
> news:F3A3AFE1-D8E9-4802-9AEC-BB038FD4A946@microsoft.com...
> >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?
>
>
Back to top
Login to vote
adsh02138




Joined: Jan 21, 2009
Posts: 1



(Msg. 4) Posted: Wed Jan 21, 2009 8:26 am
Post subject: Re: Moving email attachment into inbox... [Login to view extended thread Info.]

I also used your code to do a very similar task. It works fine for me but the messages arrive in the inbox as new (i.e. draft) messages. Is there a way to show them as received emails?
(BTW the "itemnew.UnRead = True" works for me.)
I am a near total beginner.

Regards,
Back to top
Login to vote
Aaron

External


Since: Mar 03, 2006
Posts: 83



(Msg. 5) Posted: Mon Feb 09, 2009 11:07 am
Post subject: Re: Moving email attachment into inbox... [Login to view extended thread Info.]
Archived from groups: microsoft>public>outlook>program_vba (more info?)

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

"Ken Slovak - [MVP - Outlook]" wrote:

> 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.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "Bennett" <Bennett RemoveThis @discussions.microsoft.com> wrote in message
> news:F3A3AFE1-D8E9-4802-9AEC-BB038FD4A946@microsoft.com...
> >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?
>
>
Back to top
Login to vote
Ken Slovak - [MVP - Outlo

External


Since: Oct 17, 2003
Posts: 2999



(Msg. 6) Posted: Mon Feb 09, 2009 2:17 pm
Post subject: Re: Moving email attachment into inbox... [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Aaron" <Aaron DeleteThis @discussions.microsoft.com> wrote in message
news:981A463A-3713-4C41-AB12-C284B9FA61C9@microsoft.com...
> 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
Back to top
Login to vote
Display posts from previous:   
       Home -> Office -> Programming VBA All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows XP
 Windows Vista
 Windows Other
  Office
 Office Other
 Security
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET |
  • IT Support