Discussion:
Auto forwarding - empty bodies
(too old to reply)
badatvba
2009-06-22 13:37:02 UTC
Permalink
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("***@googlemail.com")
oRecip.Resolve

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

myItem.Send

End If

End Sub
Ken Slovak - [MVP - Outlook]
2009-06-22 13:48:30 UTC
Permalink
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
Post by 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 =
oRecip.Resolve
'mybody = Item.body
myItem.body = mybody
myItem.Subject = Item.Subject
myItem.Send
End If
End Sub
badatvba
2009-06-23 08:41:01 UTC
Permalink
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
Post by Ken Slovak - [MVP - Outlook]
Body is always the plain text message text, in whatever type of item
(original, read, reply, forward, etc.).
' 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
Post by 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 =
oRecip.Resolve
'mybody = Item.body
myItem.body = mybody
myItem.Subject = Item.Subject
myItem.Send
End If
End Sub
Ken Slovak - [MVP - Outlook]
2009-06-23 12:58:33 UTC
Permalink
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
Post by 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
badatvba
2009-07-01 15:46:01 UTC
Permalink
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
Post by 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
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
Post by 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
Ken Slovak - [MVP - Outlook]
2009-07-01 17:08:11 UTC
Permalink
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
Post by badatvba
Hi Ken,
thanks again for your recent assistance.
I have another question.....
- 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
Loading...