Re: Unable to add "X-Header" to a mail that is being sent...
- From: "Dmitry Streblechenko" <dmitry@xxxxxxxxxxx>
- Date: Mon, 14 May 2007 10:02:24 -0700
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" <gopi@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:42C700D2-1277-431F-A762-A7BA1B298FB9@xxxxxxxxxxxxxxxx
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 <whoever@xxxxxxxxxx>"
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" <gopi@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:6903120C-7440-44FE-B7F7-60CF92359A07@xxxxxxxxxxxxxxxx
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).Value
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
************************************************************************
.
- Follow-Ups:
- References:
- Unable to add "X-Header" to a mail that is being sent...
- From: gopi
- Re: Unable to add "X-Header" to a mail that is being sent...
- From: Dmitry Streblechenko
- Re: Unable to add "X-Header" to a mail that is being sent...
- From: gopi
- Unable to add "X-Header" to a mail that is being sent...
- Prev by Date: Re: Use of AdvancedSearch complete code
- Next by Date: Re: Identifying components of email message
- Previous by thread: Re: Unable to add "X-Header" to a mail that is being sent...
- Next by thread: Re: Unable to add "X-Header" to a mail that is being sent...
- Index(es):
Relevant Pages
|
Loading