A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Unable to add "X-Header" to a mail that is being sent...



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 11th 07, 04:16 PM posted to microsoft.public.outlook.program_vba
gopi
external usenet poster
 
Posts: 8
Default Unable to add "X-Header" to a mail that is being sent...

Environment:
-Outlook 2002(XP)
-Added references to "Microsoft Outlook 10.0 Object Library" & "Microsoft
CDO 1.21 Library"

I have written a VB project using MS Visual Basic 6.0. My intention is to
add a X-Header to a mail that is being sent from

Outlook. I am capturing the ItemSend event and trying to add the header in
that event handler.

Please find the complete source code below. Please note that the Sub
ChangeHeader() is working fine if I call it for

an existing mail in my Outlook Inbox. But I have a problem in calling this
ChangeHeader() from my ItemSend event handler, as

ChangeHeader() takes MAPI.Message as an argument, but MyOLApp_ItemSend() is
giving me Outlook.MailItem.

How do I convert Outlook.MailItem to MAPI.Message?
Or
Is there any other way to add the X-header without needing to have a
MAPI.Message object?


Thanks,
Gopi

************************************************** **********************


Public WithEvents MyOLApp As Outlook.Application

Sub Intialize_Event_Handlers()

Set MyOLApp = Application
MsgBox "Initialize Event Handlers successful"

End Sub



Private Sub Command1_Click()

Intialize_Event_Handlers

End Sub



Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

'How do I now call ChangeHeader(), which takes MAPI.Message, as an
argument!!!
'Add the custom header now
'ChangeHeader oMessage


End Sub



Sub ChangeHeader(oMessage As MAPI.Message)

' Initalize error handling
On Error Resume Next

MsgBox "ChangeHeader - BEGIN", vbInformation

Dim oFields As MAPI.Fields
Set oFields = oMessage.Fields

Dim strheader As String

' Get SMTP header
Err.Clear
strheader = oFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Valu e

If Err.Number = 0 Then
MsgBox strheader 'Display the original Internet headers

'Append the custom X-Header now!
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) =
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) & vbCrLf &

"X-MY-HEADER9: Hello"

ElseIf Err.Number = &H8004010F Then
Err.Clear
MsgBox "No SMTP message header information on this message",
vbInformation

'Add the custom X-Header now
oFields.Add CdoPR_TRANSPORT_MESSAGE_HEADERS, "X-MY-NEWHEADER: Hello"

Else
MsgBox "some vague scenario", vbInformation

End If


oMessage.Update

MsgBox "ChangeHeader - END", vbInformation

End Sub


************************************************** **********************
Ads
  #2  
Old May 11th 07, 08:22 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Unable to add "X-Header" to a mail that is being sent...

Modifying the PR_TRANSPORT_MESSAGE_HEADERS property has no effect on the
outgoing messages.
To add an X-header, you need to create a named string MAPI property with a
particular GUID.
See http://www.dimastr.com/redemption/faq.htm#14 for a Redemption example.
It shows howw to change the "From" header, but it is equally applicable to
any MME header.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Environment:
-Outlook 2002(XP)
-Added references to "Microsoft Outlook 10.0 Object Library" & "Microsoft
CDO 1.21 Library"

I have written a VB project using MS Visual Basic 6.0. My intention is to
add a X-Header to a mail that is being sent from

Outlook. I am capturing the ItemSend event and trying to add the header in
that event handler.

Please find the complete source code below. Please note that the Sub
ChangeHeader() is working fine if I call it for

an existing mail in my Outlook Inbox. But I have a problem in calling this
ChangeHeader() from my ItemSend event handler, as

ChangeHeader() takes MAPI.Message as an argument, but MyOLApp_ItemSend()
is
giving me Outlook.MailItem.

How do I convert Outlook.MailItem to MAPI.Message?
Or
Is there any other way to add the X-header without needing to have a
MAPI.Message object?


Thanks,
Gopi

************************************************** **********************


Public WithEvents MyOLApp As Outlook.Application

Sub Intialize_Event_Handlers()

Set MyOLApp = Application
MsgBox "Initialize Event Handlers successful"

End Sub



Private Sub Command1_Click()

Intialize_Event_Handlers

End Sub



Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

'How do I now call ChangeHeader(), which takes MAPI.Message, as an
argument!!!
'Add the custom header now
'ChangeHeader oMessage


End Sub



Sub ChangeHeader(oMessage As MAPI.Message)

' Initalize error handling
On Error Resume Next

MsgBox "ChangeHeader - BEGIN", vbInformation

Dim oFields As MAPI.Fields
Set oFields = oMessage.Fields

Dim strheader As String

' Get SMTP header
Err.Clear
strheader = oFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Valu e

If Err.Number = 0 Then
MsgBox strheader 'Display the original Internet headers

'Append the custom X-Header now!
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) =
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) & vbCrLf &

"X-MY-HEADER9: Hello"

ElseIf Err.Number = &H8004010F Then
Err.Clear
MsgBox "No SMTP message header information on this message",
vbInformation

'Add the custom X-Header now
oFields.Add CdoPR_TRANSPORT_MESSAGE_HEADERS, "X-MY-NEWHEADER:
Hello"

Else
MsgBox "some vague scenario", vbInformation

End If


oMessage.Update

MsgBox "ChangeHeader - END", vbInformation

End Sub


************************************************** **********************



  #3  
Old May 13th 07, 10:36 AM posted to microsoft.public.outlook.program_vba
gopi
external usenet poster
 
Posts: 8
Default Unable to add "X-Header" to a mail that is being sent...

Thanks for your response.
But unfortunately the program is crashing when the following statement is
encountered.
Tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From")

How can I fix this problem?

Please find the complete code below.

Thanks,
gopi

------------------------------------------------------------------
Public WithEvents MyOLApp As Outlook.Application
Public WithEvents MyOLItems As Outlook.Items


Sub Intialize_Event_Handlers()

Set MyOLApp = Application
Set MyOLItems = Application.Session.GetDefaultFolder(olFolderInbox ).Items

MsgBox "Initialize Event Handlers successful"

End Sub

Private Sub Command1_Click()
Intialize_Event_Handlers
End Sub

Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

Dim sItem As Redemption.SafeMailItem
Set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = myMailItem


Tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From") 'It is crashing here
Tag = Tag Or &H1E 'the type is PT_STRING8
sItem.Fields(Tag) = "Someone "
sItem.Subject = sItem.Subject 'to trick Outlook into thinking that
something has changed
sItem.Save


End Sub
-------------------------------------------------------------------



"Dmitry Streblechenko" wrote:

Modifying the PR_TRANSPORT_MESSAGE_HEADERS property has no effect on the
outgoing messages.
To add an X-header, you need to create a named string MAPI property with a
particular GUID.
See http://www.dimastr.com/redemption/faq.htm#14 for a Redemption example.
It shows howw to change the "From" header, but it is equally applicable to
any MME header.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Environment:
-Outlook 2002(XP)
-Added references to "Microsoft Outlook 10.0 Object Library" & "Microsoft
CDO 1.21 Library"

I have written a VB project using MS Visual Basic 6.0. My intention is to
add a X-Header to a mail that is being sent from

Outlook. I am capturing the ItemSend event and trying to add the header in
that event handler.

Please find the complete source code below. Please note that the Sub
ChangeHeader() is working fine if I call it for

an existing mail in my Outlook Inbox. But I have a problem in calling this
ChangeHeader() from my ItemSend event handler, as

ChangeHeader() takes MAPI.Message as an argument, but MyOLApp_ItemSend()
is
giving me Outlook.MailItem.

How do I convert Outlook.MailItem to MAPI.Message?
Or
Is there any other way to add the X-header without needing to have a
MAPI.Message object?


Thanks,
Gopi

************************************************** **********************


Public WithEvents MyOLApp As Outlook.Application

Sub Intialize_Event_Handlers()

Set MyOLApp = Application
MsgBox "Initialize Event Handlers successful"

End Sub



Private Sub Command1_Click()

Intialize_Event_Handlers

End Sub



Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

'How do I now call ChangeHeader(), which takes MAPI.Message, as an
argument!!!
'Add the custom header now
'ChangeHeader oMessage


End Sub



Sub ChangeHeader(oMessage As MAPI.Message)

' Initalize error handling
On Error Resume Next

MsgBox "ChangeHeader - BEGIN", vbInformation

Dim oFields As MAPI.Fields
Set oFields = oMessage.Fields

Dim strheader As String

' Get SMTP header
Err.Clear
strheader = oFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Valu e

If Err.Number = 0 Then
MsgBox strheader 'Display the original Internet headers

'Append the custom X-Header now!
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) =
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) & vbCrLf &

"X-MY-HEADER9: Hello"

ElseIf Err.Number = &H8004010F Then
Err.Clear
MsgBox "No SMTP message header information on this message",
vbInformation

'Add the custom X-Header now
oFields.Add CdoPR_TRANSPORT_MESSAGE_HEADERS, "X-MY-NEWHEADER:
Hello"

Else
MsgBox "some vague scenario", vbInformation

End If


oMessage.Update

MsgBox "ChangeHeader - END", vbInformation

End Sub


************************************************** **********************




  #4  
Old May 14th 07, 07:02 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Unable to add "X-Header" to a mail that is being sent...

Crashing as in producing an access violation or as in "returning a COM
error"? In the latter case, what is the error?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Thanks for your response.
But unfortunately the program is crashing when the following statement is
encountered.
Tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From")

How can I fix this problem?

Please find the complete code below.

Thanks,
gopi

------------------------------------------------------------------
Public WithEvents MyOLApp As Outlook.Application
Public WithEvents MyOLItems As Outlook.Items


Sub Intialize_Event_Handlers()

Set MyOLApp = Application
Set MyOLItems =
Application.Session.GetDefaultFolder(olFolderInbox ).Items

MsgBox "Initialize Event Handlers successful"

End Sub

Private Sub Command1_Click()
Intialize_Event_Handlers
End Sub

Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

Dim sItem As Redemption.SafeMailItem
Set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = myMailItem


Tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From") 'It is crashing here
Tag = Tag Or &H1E 'the type is PT_STRING8
sItem.Fields(Tag) = "Someone "
sItem.Subject = sItem.Subject 'to trick Outlook into thinking that
something has changed
sItem.Save


End Sub
-------------------------------------------------------------------



"Dmitry Streblechenko" wrote:

Modifying the PR_TRANSPORT_MESSAGE_HEADERS property has no effect on the
outgoing messages.
To add an X-header, you need to create a named string MAPI property with
a
particular GUID.
See http://www.dimastr.com/redemption/faq.htm#14 for a Redemption
example.
It shows howw to change the "From" header, but it is equally applicable
to
any MME header.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Environment:
-Outlook 2002(XP)
-Added references to "Microsoft Outlook 10.0 Object Library" &
"Microsoft
CDO 1.21 Library"

I have written a VB project using MS Visual Basic 6.0. My intention is
to
add a X-Header to a mail that is being sent from

Outlook. I am capturing the ItemSend event and trying to add the header
in
that event handler.

Please find the complete source code below. Please note that the Sub
ChangeHeader() is working fine if I call it for

an existing mail in my Outlook Inbox. But I have a problem in calling
this
ChangeHeader() from my ItemSend event handler, as

ChangeHeader() takes MAPI.Message as an argument, but
MyOLApp_ItemSend()
is
giving me Outlook.MailItem.

How do I convert Outlook.MailItem to MAPI.Message?
Or
Is there any other way to add the X-header without needing to have a
MAPI.Message object?


Thanks,
Gopi

************************************************** **********************


Public WithEvents MyOLApp As Outlook.Application

Sub Intialize_Event_Handlers()

Set MyOLApp = Application
MsgBox "Initialize Event Handlers successful"

End Sub



Private Sub Command1_Click()

Intialize_Event_Handlers

End Sub



Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

'How do I now call ChangeHeader(), which takes MAPI.Message, as an
argument!!!
'Add the custom header now
'ChangeHeader oMessage


End Sub



Sub ChangeHeader(oMessage As MAPI.Message)

' Initalize error handling
On Error Resume Next

MsgBox "ChangeHeader - BEGIN", vbInformation

Dim oFields As MAPI.Fields
Set oFields = oMessage.Fields

Dim strheader As String

' Get SMTP header
Err.Clear
strheader = oFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Valu e

If Err.Number = 0 Then
MsgBox strheader 'Display the original Internet headers

'Append the custom X-Header now!
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) =
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) & vbCrLf &

"X-MY-HEADER9: Hello"

ElseIf Err.Number = &H8004010F Then
Err.Clear
MsgBox "No SMTP message header information on this message",
vbInformation

'Add the custom X-Header now
oFields.Add CdoPR_TRANSPORT_MESSAGE_HEADERS, "X-MY-NEWHEADER:
Hello"

Else
MsgBox "some vague scenario", vbInformation

End If


oMessage.Update

MsgBox "ChangeHeader - END", vbInformation

End Sub


************************************************** **********************






  #5  
Old May 15th 07, 06:38 AM posted to microsoft.public.outlook.program_vba
gopi
external usenet poster
 
Posts: 8
Default Unable to add "X-Header" to a mail that is being sent...

Here is the exact error message I am getting:

[
Microsoft Visual Basic
--------------------------

Run-time error '-2147418113 (8000ffff)':
Error in _HrGetIDsFromNames - IMAPIProp == NULL
]

Thanks.

"Dmitry Streblechenko" wrote:

Crashing as in producing an access violation or as in "returning a COM
error"? In the latter case, what is the error?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Thanks for your response.
But unfortunately the program is crashing when the following statement is
encountered.
Tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From")

How can I fix this problem?

Please find the complete code below.

Thanks,
gopi

------------------------------------------------------------------
Public WithEvents MyOLApp As Outlook.Application
Public WithEvents MyOLItems As Outlook.Items


Sub Intialize_Event_Handlers()

Set MyOLApp = Application
Set MyOLItems =
Application.Session.GetDefaultFolder(olFolderInbox ).Items

MsgBox "Initialize Event Handlers successful"

End Sub

Private Sub Command1_Click()
Intialize_Event_Handlers
End Sub

Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

Dim sItem As Redemption.SafeMailItem
Set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = myMailItem


Tag = sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From") 'It is crashing here
Tag = Tag Or &H1E 'the type is PT_STRING8
sItem.Fields(Tag) = "Someone "
sItem.Subject = sItem.Subject 'to trick Outlook into thinking that
something has changed
sItem.Save


End Sub
-------------------------------------------------------------------



"Dmitry Streblechenko" wrote:

Modifying the PR_TRANSPORT_MESSAGE_HEADERS property has no effect on the
outgoing messages.
To add an X-header, you need to create a named string MAPI property with
a
particular GUID.
See http://www.dimastr.com/redemption/faq.htm#14 for a Redemption
example.
It shows howw to change the "From" header, but it is equally applicable
to
any MME header.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Environment:
-Outlook 2002(XP)
-Added references to "Microsoft Outlook 10.0 Object Library" &
"Microsoft
CDO 1.21 Library"

I have written a VB project using MS Visual Basic 6.0. My intention is
to
add a X-Header to a mail that is being sent from

Outlook. I am capturing the ItemSend event and trying to add the header
in
that event handler.

Please find the complete source code below. Please note that the Sub
ChangeHeader() is working fine if I call it for

an existing mail in my Outlook Inbox. But I have a problem in calling
this
ChangeHeader() from my ItemSend event handler, as

ChangeHeader() takes MAPI.Message as an argument, but
MyOLApp_ItemSend()
is
giving me Outlook.MailItem.

How do I convert Outlook.MailItem to MAPI.Message?
Or
Is there any other way to add the X-header without needing to have a
MAPI.Message object?


Thanks,
Gopi

************************************************** **********************


Public WithEvents MyOLApp As Outlook.Application

Sub Intialize_Event_Handlers()

Set MyOLApp = Application
MsgBox "Initialize Event Handlers successful"

End Sub



Private Sub Command1_Click()

Intialize_Event_Handlers

End Sub



Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)

MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

'How do I now call ChangeHeader(), which takes MAPI.Message, as an
argument!!!
'Add the custom header now
'ChangeHeader oMessage


End Sub



Sub ChangeHeader(oMessage As MAPI.Message)

' Initalize error handling
On Error Resume Next

MsgBox "ChangeHeader - BEGIN", vbInformation

Dim oFields As MAPI.Fields
Set oFields = oMessage.Fields

Dim strheader As String

' Get SMTP header
Err.Clear
strheader = oFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Valu e

If Err.Number = 0 Then
MsgBox strheader 'Display the original Internet headers

'Append the custom X-Header now!
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) =
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) & vbCrLf &

"X-MY-HEADER9: Hello"

ElseIf Err.Number = &H8004010F Then
Err.Clear
MsgBox "No SMTP message header information on this message",
vbInformation

'Add the custom X-Header now
oFields.Add CdoPR_TRANSPORT_MESSAGE_HEADERS, "X-MY-NEWHEADER:
Hello"

Else
MsgBox "some vague scenario", vbInformation

End If


oMessage.Update

MsgBox "ChangeHeader - END", vbInformation

End Sub


************************************************** **********************






  #6  
Old May 15th 07, 08:05 AM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Unable to add "X-Header" to a mail that is being sent...

What is your version of Outlook? Do you by by chance have both Outlook and
Exchange Server installed on the same machine?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Here is the exact error message I am getting:

[
Microsoft Visual Basic
--------------------------

Run-time error '-2147418113 (8000ffff)':
Error in _HrGetIDsFromNames - IMAPIProp == NULL
]

Thanks.

"Dmitry Streblechenko" wrote:

Crashing as in producing an access violation or as in "returning a COM
error"? In the latter case, what is the error?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Thanks for your response.
But unfortunately the program is crashing when the following statement
is
encountered.
Tag =
sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From")

How can I fix this problem?

Please find the complete code below.

Thanks,
gopi

------------------------------------------------------------------
Public WithEvents MyOLApp As Outlook.Application
Public WithEvents MyOLItems As Outlook.Items


Sub Intialize_Event_Handlers()

Set MyOLApp = Application
Set MyOLItems =
Application.Session.GetDefaultFolder(olFolderInbox ).Items

MsgBox "Initialize Event Handlers successful"

End Sub

Private Sub Command1_Click()
Intialize_Event_Handlers
End Sub

Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

Dim sItem As Redemption.SafeMailItem
Set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = myMailItem


Tag =
sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From") 'It is crashing here
Tag = Tag Or &H1E 'the type is PT_STRING8
sItem.Fields(Tag) = "Someone "
sItem.Subject = sItem.Subject 'to trick Outlook into thinking that
something has changed
sItem.Save


End Sub
-------------------------------------------------------------------



"Dmitry Streblechenko" wrote:

Modifying the PR_TRANSPORT_MESSAGE_HEADERS property has no effect on
the
outgoing messages.
To add an X-header, you need to create a named string MAPI property
with
a
particular GUID.
See http://www.dimastr.com/redemption/faq.htm#14 for a Redemption
example.
It shows howw to change the "From" header, but it is equally
applicable
to
any MME header.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Environment:
-Outlook 2002(XP)
-Added references to "Microsoft Outlook 10.0 Object Library" &
"Microsoft
CDO 1.21 Library"

I have written a VB project using MS Visual Basic 6.0. My intention
is
to
add a X-Header to a mail that is being sent from

Outlook. I am capturing the ItemSend event and trying to add the
header
in
that event handler.

Please find the complete source code below. Please note that the Sub
ChangeHeader() is working fine if I call it for

an existing mail in my Outlook Inbox. But I have a problem in
calling
this
ChangeHeader() from my ItemSend event handler, as

ChangeHeader() takes MAPI.Message as an argument, but
MyOLApp_ItemSend()
is
giving me Outlook.MailItem.

How do I convert Outlook.MailItem to MAPI.Message?
Or
Is there any other way to add the X-header without needing to have a
MAPI.Message object?


Thanks,
Gopi

************************************************** **********************


Public WithEvents MyOLApp As Outlook.Application

Sub Intialize_Event_Handlers()

Set MyOLApp = Application
MsgBox "Initialize Event Handlers successful"

End Sub



Private Sub Command1_Click()

Intialize_Event_Handlers

End Sub



Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As
Boolean)

MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

'How do I now call ChangeHeader(), which takes MAPI.Message, as
an
argument!!!
'Add the custom header now
'ChangeHeader oMessage


End Sub



Sub ChangeHeader(oMessage As MAPI.Message)

' Initalize error handling
On Error Resume Next

MsgBox "ChangeHeader - BEGIN", vbInformation

Dim oFields As MAPI.Fields
Set oFields = oMessage.Fields

Dim strheader As String

' Get SMTP header
Err.Clear
strheader = oFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Valu e

If Err.Number = 0 Then
MsgBox strheader 'Display the original Internet headers

'Append the custom X-Header now!
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) =
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) & vbCrLf &

"X-MY-HEADER9: Hello"

ElseIf Err.Number = &H8004010F Then
Err.Clear
MsgBox "No SMTP message header information on this message",
vbInformation

'Add the custom X-Header now
oFields.Add CdoPR_TRANSPORT_MESSAGE_HEADERS, "X-MY-NEWHEADER:
Hello"

Else
MsgBox "some vague scenario", vbInformation

End If


oMessage.Update

MsgBox "ChangeHeader - END", vbInformation

End Sub


************************************************** **********************








  #7  
Old May 15th 07, 09:13 AM posted to microsoft.public.outlook.program_vba
gopi
external usenet poster
 
Posts: 8
Default Unable to add "X-Header" to a mail that is being sent...

I am using Outlook 2002 (10.2627.2625).
Yes, I have Exchange 2003 and Outlook 2002 installed on the same machine.

Thanks.

"Dmitry Streblechenko" wrote:

What is your version of Outlook? Do you by by chance have both Outlook and
Exchange Server installed on the same machine?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Here is the exact error message I am getting:

[
Microsoft Visual Basic
--------------------------

Run-time error '-2147418113 (8000ffff)':
Error in _HrGetIDsFromNames - IMAPIProp == NULL
]

Thanks.

"Dmitry Streblechenko" wrote:

Crashing as in producing an access violation or as in "returning a COM
error"? In the latter case, what is the error?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Thanks for your response.
But unfortunately the program is crashing when the following statement
is
encountered.
Tag =
sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From")

How can I fix this problem?

Please find the complete code below.

Thanks,
gopi

------------------------------------------------------------------
Public WithEvents MyOLApp As Outlook.Application
Public WithEvents MyOLItems As Outlook.Items


Sub Intialize_Event_Handlers()

Set MyOLApp = Application
Set MyOLItems =
Application.Session.GetDefaultFolder(olFolderInbox ).Items

MsgBox "Initialize Event Handlers successful"

End Sub

Private Sub Command1_Click()
Intialize_Event_Handlers
End Sub

Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As Boolean)
MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

Dim sItem As Redemption.SafeMailItem
Set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = myMailItem


Tag =
sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From") 'It is crashing here
Tag = Tag Or &H1E 'the type is PT_STRING8
sItem.Fields(Tag) = "Someone "
sItem.Subject = sItem.Subject 'to trick Outlook into thinking that
something has changed
sItem.Save


End Sub
-------------------------------------------------------------------



"Dmitry Streblechenko" wrote:

Modifying the PR_TRANSPORT_MESSAGE_HEADERS property has no effect on
the
outgoing messages.
To add an X-header, you need to create a named string MAPI property
with
a
particular GUID.
See http://www.dimastr.com/redemption/faq.htm#14 for a Redemption
example.
It shows howw to change the "From" header, but it is equally
applicable
to
any MME header.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Environment:
-Outlook 2002(XP)
-Added references to "Microsoft Outlook 10.0 Object Library" &
"Microsoft
CDO 1.21 Library"

I have written a VB project using MS Visual Basic 6.0. My intention
is
to
add a X-Header to a mail that is being sent from

Outlook. I am capturing the ItemSend event and trying to add the
header
in
that event handler.

Please find the complete source code below. Please note that the Sub
ChangeHeader() is working fine if I call it for

an existing mail in my Outlook Inbox. But I have a problem in
calling
this
ChangeHeader() from my ItemSend event handler, as

ChangeHeader() takes MAPI.Message as an argument, but
MyOLApp_ItemSend()
is
giving me Outlook.MailItem.

How do I convert Outlook.MailItem to MAPI.Message?
Or
Is there any other way to add the X-header without needing to have a
MAPI.Message object?


Thanks,
Gopi

************************************************** **********************


Public WithEvents MyOLApp As Outlook.Application

Sub Intialize_Event_Handlers()

Set MyOLApp = Application
MsgBox "Initialize Event Handlers successful"

End Sub



Private Sub Command1_Click()

Intialize_Event_Handlers

End Sub



Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As
Boolean)

MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

'How do I now call ChangeHeader(), which takes MAPI.Message, as
an
argument!!!
'Add the custom header now
'ChangeHeader oMessage


End Sub



Sub ChangeHeader(oMessage As MAPI.Message)

' Initalize error handling
On Error Resume Next

MsgBox "ChangeHeader - BEGIN", vbInformation

Dim oFields As MAPI.Fields
Set oFields = oMessage.Fields

Dim strheader As String

' Get SMTP header
Err.Clear
strheader = oFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Valu e

If Err.Number = 0 Then
MsgBox strheader 'Display the original Internet headers

'Append the custom X-Header now!
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) =
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) & vbCrLf &

"X-MY-HEADER9: Hello"

ElseIf Err.Number = &H8004010F Then
Err.Clear
MsgBox "No SMTP message header information on this message",
vbInformation

'Add the custom X-Header now
oFields.Add CdoPR_TRANSPORT_MESSAGE_HEADERS, "X-MY-NEWHEADER:
Hello"

Else
MsgBox "some vague scenario", vbInformation

End If


oMessage.Update

MsgBox "ChangeHeader - END", vbInformation

End Sub


************************************************** **********************









  #8  
Old May 15th 07, 06:55 PM posted to microsoft.public.outlook.program_vba
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Unable to add "X-Header" to a mail that is being sent...

Such a configuration is not supported by MS: both Outlook and Exchange
install their own incompativle versions of MAPI. In this particular case,
Redemption ends up using the Exchange version of MAPI, so the marshalling of
MAPI objects does not work correctly.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
I am using Outlook 2002 (10.2627.2625).
Yes, I have Exchange 2003 and Outlook 2002 installed on the same machine.

Thanks.

"Dmitry Streblechenko" wrote:

What is your version of Outlook? Do you by by chance have both Outlook
and
Exchange Server installed on the same machine?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Here is the exact error message I am getting:

[
Microsoft Visual Basic
--------------------------

Run-time error '-2147418113 (8000ffff)':
Error in _HrGetIDsFromNames - IMAPIProp == NULL
]

Thanks.

"Dmitry Streblechenko" wrote:

Crashing as in producing an access violation or as in "returning a COM
error"? In the latter case, what is the error?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Thanks for your response.
But unfortunately the program is crashing when the following
statement
is
encountered.
Tag =
sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From")

How can I fix this problem?

Please find the complete code below.

Thanks,
gopi

------------------------------------------------------------------
Public WithEvents MyOLApp As Outlook.Application
Public WithEvents MyOLItems As Outlook.Items


Sub Intialize_Event_Handlers()

Set MyOLApp = Application
Set MyOLItems =
Application.Session.GetDefaultFolder(olFolderInbox ).Items

MsgBox "Initialize Event Handlers successful"

End Sub

Private Sub Command1_Click()
Intialize_Event_Handlers
End Sub

Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As
Boolean)
MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

Dim sItem As Redemption.SafeMailItem
Set sItem = CreateObject("Redemption.SafeMailItem")
sItem.Item = myMailItem


Tag =
sItem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"From") 'It is crashing here
Tag = Tag Or &H1E 'the type is PT_STRING8
sItem.Fields(Tag) = "Someone "
sItem.Subject = sItem.Subject 'to trick Outlook into thinking
that
something has changed
sItem.Save


End Sub
-------------------------------------------------------------------



"Dmitry Streblechenko" wrote:

Modifying the PR_TRANSPORT_MESSAGE_HEADERS property has no effect
on
the
outgoing messages.
To add an X-header, you need to create a named string MAPI property
with
a
particular GUID.
See http://www.dimastr.com/redemption/faq.htm#14 for a Redemption
example.
It shows howw to change the "From" header, but it is equally
applicable
to
any MME header.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"gopi" wrote in message
...
Environment:
-Outlook 2002(XP)
-Added references to "Microsoft Outlook 10.0 Object Library" &
"Microsoft
CDO 1.21 Library"

I have written a VB project using MS Visual Basic 6.0. My
intention
is
to
add a X-Header to a mail that is being sent from

Outlook. I am capturing the ItemSend event and trying to add the
header
in
that event handler.

Please find the complete source code below. Please note that the
Sub
ChangeHeader() is working fine if I call it for

an existing mail in my Outlook Inbox. But I have a problem in
calling
this
ChangeHeader() from my ItemSend event handler, as

ChangeHeader() takes MAPI.Message as an argument, but
MyOLApp_ItemSend()
is
giving me Outlook.MailItem.

How do I convert Outlook.MailItem to MAPI.Message?
Or
Is there any other way to add the X-header without needing to
have a
MAPI.Message object?


Thanks,
Gopi

************************************************** **********************


Public WithEvents MyOLApp As Outlook.Application

Sub Intialize_Event_Handlers()

Set MyOLApp = Application
MsgBox "Initialize Event Handlers successful"

End Sub



Private Sub Command1_Click()

Intialize_Event_Handlers

End Sub



Private Sub MyOLApp_ItemSend(ByVal Item As Object, Cancel As
Boolean)

MsgBox "I am in ItemSend handler"

Dim myMailItem As Outlook.MailItem
Set myMailItem = Item

MsgBox myMailItem.Subject

'How do I now call ChangeHeader(), which takes MAPI.Message,
as
an
argument!!!
'Add the custom header now
'ChangeHeader oMessage


End Sub



Sub ChangeHeader(oMessage As MAPI.Message)

' Initalize error handling
On Error Resume Next

MsgBox "ChangeHeader - BEGIN", vbInformation

Dim oFields As MAPI.Fields
Set oFields = oMessage.Fields

Dim strheader As String

' Get SMTP header
Err.Clear
strheader =
oFields.Item(CdoPR_TRANSPORT_MESSAGE_HEADERS).Valu e

If Err.Number = 0 Then
MsgBox strheader 'Display the original Internet headers

'Append the custom X-Header now!
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) =
oMessage.Fields(CdoPR_TRANSPORT_MESSAGE_HEADERS) & vbCrLf &

"X-MY-HEADER9: Hello"

ElseIf Err.Number = &H8004010F Then
Err.Clear
MsgBox "No SMTP message header information on this
message",
vbInformation

'Add the custom X-Header now
oFields.Add CdoPR_TRANSPORT_MESSAGE_HEADERS,
"X-MY-NEWHEADER:
Hello"

Else
MsgBox "some vague scenario", vbInformation

End If


oMessage.Update

MsgBox "ChangeHeader - END", vbInformation

End Sub


************************************************** **********************











 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
"Unable to open your default e-mail folders" error after Outlo paul Outlook - Installation 5 November 23rd 07 06:07 PM
"Unable to open your default e-mail folders..." error paul Outlook - Installation 6 August 20th 06 05:44 PM
Showing RFC822 "From" header in Messages pane "From" column Ken Wallewein Outlook - General Queries 0 July 22nd 06 05:47 PM
"Unable to open default e-mail folders" Alexander Bryant Outlook - Installation 0 June 21st 06 08:26 PM
"Reply-To:" header in OE mail messages ggull Outlook Express 18 May 9th 06 10:01 PM


All times are GMT +1. The time now is 12:56 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.