Home All Groups Group Topic Archive Search About

Auto forwarding - empty bodies

Author
22 Jun 2009 1:37 PM
badatvba

Hi,

I am using the below code (thanks to Ken Slovak!!) to redirect mail from my
OL email to my googlemail account. It works fine except for mail items which
have been replied to or forwarded - I get the message & subject but the body
is empty.
Is there a different attribute name for the body for forwarded/replied OL
mails?

many thanks
----------------------------------------------------------------------------------
Public WithEvents myOlItems As Outlook.Items

Public Sub Application_Startup()

   ' Reference the items in the Inbox. Because myOlItems is declared
   ' "WithEvents" the ItemAdd event will fire below.
   MsgBox "Running Application_Startup"
   Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items

End Sub

Private Sub myOlItems_ItemAdd(ByVal Item As Object)



      ' Check to make sure it is an Outlook mail message, otherwise
      ' subsequent code will probably fail depending on what type
      ' of item it is.
      If TypeName(Item) = "MailItem" Then

      'Extract info from the mailItem
        Set myItem = Application.CreateItem(olMailItem)
        Dim oRecip As Outlook.Recipient
        Set oRecip = myItem.Recipients.Add("alastair.can***@googlemail.com")
        oRecip.Resolve

       'mybody = Item.body
        myItem.body = mybody
        myItem.Subject = Item.Subject

        myItem.Send

      End If

End Sub
Author
22 Jun 2009 1:48 PM
Ken Slovak - [MVP - Outlook]
Body is always the plain text message text, in whatever type of item
(original, read, reply, forward, etc.).

Are these HTML messages? Test in the code for something like this:

' other code
oRecip.Resolve

If Item.BodyFormat = olFormatHTML Then
    myItem.HTMLBody = Item.HTMLBody
Else
    myItem.Body = Item.Body
End If

Commenting out the line where you assign mybody = Item.Body would leave
mybody as a null string, so unless you are setting the "mybody" variable
somewhere else that could be the problem.

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


Show quoteHide quote
"badatvba" <badat***@discussions.microsoft.com> wrote in message
news:92BF98D5-BB19-4C4E-B71B-8842DB04D18E@microsoft.com...
> Hi,
>
> I am using the below code (thanks to Ken Slovak!!) to redirect mail from
> my
> OL email to my googlemail account. It works fine except for mail items
> which
> have been replied to or forwarded - I get the message & subject but the
> body
> is empty.
> Is there a different attribute name for the body for forwarded/replied OL
> mails?
>
> many thanks
>
> ----------------------------------------------------------------------------------
> Public WithEvents myOlItems As Outlook.Items
>
> Public Sub Application_Startup()
>
>   ' Reference the items in the Inbox. Because myOlItems is declared
>   ' "WithEvents" the ItemAdd event will fire below.
>   MsgBox "Running Application_Startup"
>   Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
>
> End Sub
>
> Private Sub myOlItems_ItemAdd(ByVal Item As Object)
>
>
>
>      ' Check to make sure it is an Outlook mail message, otherwise
>      ' subsequent code will probably fail depending on what type
>      ' of item it is.
>      If TypeName(Item) = "MailItem" Then
>
>      'Extract info from the mailItem
>        Set myItem = Application.CreateItem(olMailItem)
>        Dim oRecip As Outlook.Recipient
>        Set oRecip =
> myItem.Recipients.Add("alastair.can***@googlemail.com")
>        oRecip.Resolve
>
>       'mybody = Item.body
>        myItem.body = mybody
>        myItem.Subject = Item.Subject
>
>        myItem.Send
>
>      End If
>
> End Sub
>
>
Are all your drivers up to date? click for free checkup

Author
23 Jun 2009 8:41 AM
badatvba
Hi Ken
thanks for all the assistance you have already given me. I understand C but
OO is still a bit of a blind spot at present.

Could you give me some guidance as to the code which will interrogate the
InBox on start up of OL looking for unread messages and then apply the
existing code I have to forward them 'after the fact'.

BTW - I have no Idea why I commented out the the line you highlighted to me
in your previous replay - must of had a bad day.............!!??

cheers Alastair

Show quoteHide quote
"Ken Slovak - [MVP - Outlook]" wrote:

> Body is always the plain text message text, in whatever type of item
> (original, read, reply, forward, etc.).
>
> Are these HTML messages? Test in the code for something like this:
>
> ' other code
> oRecip.Resolve
>
> If Item.BodyFormat = olFormatHTML Then
>     myItem.HTMLBody = Item.HTMLBody
> Else
>     myItem.Body = Item.Body
> End If
>
> Commenting out the line where you assign mybody = Item.Body would leave
> mybody as a null string, so unless you are setting the "mybody" variable
> somewhere else that could be the problem.
>
> --
> 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
>
>
> "badatvba" <badat***@discussions.microsoft.com> wrote in message
> news:92BF98D5-BB19-4C4E-B71B-8842DB04D18E@microsoft.com...
> > Hi,
> >
> > I am using the below code (thanks to Ken Slovak!!) to redirect mail from
> > my
> > OL email to my googlemail account. It works fine except for mail items
> > which
> > have been replied to or forwarded - I get the message & subject but the
> > body
> > is empty.
> > Is there a different attribute name for the body for forwarded/replied OL
> > mails?
> >
> > many thanks
> >
> > ----------------------------------------------------------------------------------
> > Public WithEvents myOlItems As Outlook.Items
> >
> > Public Sub Application_Startup()
> >
> >   ' Reference the items in the Inbox. Because myOlItems is declared
> >   ' "WithEvents" the ItemAdd event will fire below.
> >   MsgBox "Running Application_Startup"
> >   Set myOlItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items
> >
> > End Sub
> >
> > Private Sub myOlItems_ItemAdd(ByVal Item As Object)
> >
> >
> >
> >      ' Check to make sure it is an Outlook mail message, otherwise
> >      ' subsequent code will probably fail depending on what type
> >      ' of item it is.
> >      If TypeName(Item) = "MailItem" Then
> >
> >      'Extract info from the mailItem
> >        Set myItem = Application.CreateItem(olMailItem)
> >        Dim oRecip As Outlook.Recipient
> >        Set oRecip =
> > myItem.Recipients.Add("alastair.can***@googlemail.com")
> >        oRecip.Resolve
> >
> >       'mybody = Item.body
> >        myItem.body = mybody
> >        myItem.Subject = Item.Subject
> >
> >        myItem.Send
> >
> >      End If
> >
> > End Sub
> >
> >
>
>
Author
23 Jun 2009 12:58 PM
Ken Slovak - [MVP - Outlook]
If you place your code into the ThisOutlookSession class module and use the
Application_Startup() event that's exposed there for you that will run when
Outlook is started. The code would look something like this:

Private Sub Application_Startup()
    Dim colUnRead As Outlook.Items
    Dim colInbox As Outlook.Items
    Dim sFilter As String
    Dim i As Long

    sFilter = "[UnRead] = 'True' And [MessageClass] = 'IPM.Note'"

    Set colInbox = Application.Session.GetDefaultFolder(olFolderInbox).Items
    Set colUnRead = colInbox.Restrict(sFilter)

    ' colUnRead is a collection of all unread items in Inbox that are emails
    For i = colUnRead.Count To 1 Step -1
        ' do whatever with each of these items
    Next
End Sub

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


Show quoteHide quote
"badatvba" <badat***@discussions.microsoft.com> wrote in message
news:1146D598-70C4-4D95-8D6B-B210F172F6DC@microsoft.com...
> Hi Ken
> thanks for all the assistance you have already given me. I understand C
> but
> OO is still a bit of a blind spot at present.
>
> Could you give me some guidance as to the code which will interrogate the
> InBox on start up of OL looking for unread messages and then apply the
> existing code I have to forward them 'after the fact'.
>
> BTW - I have no Idea why I commented out the the line you highlighted to
> me
> in your previous replay - must of had a bad day.............!!??
>
> cheers Alastair
Author
1 Jul 2009 3:46 PM
badatvba
Hi Ken,

thanks again for your recent assistance.

I have another question.....

Is is programatically possible that:

- on receipt of a forwarded message via the code you have already assisted
me with....
- I can send a message *back* to the Outlook serverwhich will then.....
- create new message from the body  of the message I have sent back and...
- send it as if it has come from the Outlook server?

I guess I would need to specify destinataion email, subject and body via
keywords the VBA could recognise and recognise.

Thanks again
Alastair


Show quoteHide quote
"Ken Slovak - [MVP - Outlook]" wrote:

> If you place your code into the ThisOutlookSession class module and use the
> Application_Startup() event that's exposed there for you that will run when
> Outlook is started. The code would look something like this:
>
> Private Sub Application_Startup()
>     Dim colUnRead As Outlook.Items
>     Dim colInbox As Outlook.Items
>     Dim sFilter As String
>     Dim i As Long
>
>     sFilter = "[UnRead] = 'True' And [MessageClass] = 'IPM.Note'"
>
>     Set colInbox = Application.Session.GetDefaultFolder(olFolderInbox).Items
>     Set colUnRead = colInbox.Restrict(sFilter)
>
>     ' colUnRead is a collection of all unread items in Inbox that are emails
>     For i = colUnRead.Count To 1 Step -1
>         ' do whatever with each of these items
>     Next
> End Sub
>
> --
> 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
>
>
> "badatvba" <badat***@discussions.microsoft.com> wrote in message
> news:1146D598-70C4-4D95-8D6B-B210F172F6DC@microsoft.com...
> > Hi Ken
> > thanks for all the assistance you have already given me. I understand C
> > but
> > OO is still a bit of a blind spot at present.
> >
> > Could you give me some guidance as to the code which will interrogate the
> > InBox on start up of OL looking for unread messages and then apply the
> > existing code I have to forward them 'after the fact'.
> >
> > BTW - I have no Idea why I commented out the the line you highlighted to
> > me
> > in your previous replay - must of had a bad day.............!!??
> >
> > cheers Alastair
>
>
Author
1 Jul 2009 5:08 PM
Ken Slovak - [MVP - Outlook]
What Outlook server? You can certainly write code that would handle receipt
of messages into Inbox and do whatever with them, including replying to any
forwards.

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


Show quoteHide quote
"badatvba" <badat***@discussions.microsoft.com> wrote in message
news:5556B01C-70ED-4DC5-9849-ABB15E74A96D@microsoft.com...
> Hi Ken,
>
> thanks again for your recent assistance.
>
> I have another question.....
>
> Is is programatically possible that:
>
> - on receipt of a forwarded message via the code you have already assisted
> me with....
> - I can send a message *back* to the Outlook serverwhich will then.....
> - create new message from the body  of the message I have sent back and...
> - send it as if it has come from the Outlook server?
>
> I guess I would need to specify destinataion email, subject and body via
> keywords the VBA could recognise and recognise.
>
> Thanks again
> Alastair

Bookmark and Share