PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook Program Addins How to add Custom Header to Mail Item

Reply

How to add Custom Header to Mail Item

 
Thread Tools Rate Thread
Old 03-04-2006, 02:15 PM   #1
racni
Guest
 
Posts: n/a
Default How to add Custom Header to Mail Item


I can not add the custom headers. It runs without giving any errors.
But it did not change the header. If is some thing wrong with my C#
code



Please have a look at following code



"x-test-header" header is not added to the email





1 Type t = Type.GetTypeFromProgID("Redemption.SafeMailItem");


2 Redemption.SafeMailItem sitem = (Redemption.SafeMailItem)
Activator.CreateInstance(t);

3 sitem.Item = this.myMailItem;

4 int i =
sitem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"x-test-header");

5 sitem.set_Fields(i,"hello");

6 SetPropValue(sitem, "Subject", "Testing Redemption");

7 sitem.Send();





Please see the line number 4 . I m not sure abut it , because in the
vb6 code it is the 8 bit string as to my knowledge . But I do not know
the logic behind it . so how we are going to deal with this in c#.



Can you help me regarding this



This is the method I used for the change the subject field



private static void SetPropValue(object item, string
propertyName,

object propertyValue)

{

try

{

object[] args = new Object[1];

args[0] = propertyValue;

Type type = item.GetType();

type.InvokeMember(

propertyName,

BindingFlags.Public |
BindingFlags.SetField |

BindingFlags.SetProperty,

null,

item,

args);

}

catch (SystemException ex)

{

Console.WriteLine(

string.Format(

"SetPropValue for {0} Exception:
{1} ",

propertyName, ex.Message));

}

return;

}

  Reply With Quote
Old 03-04-2006, 07:02 PM   #2
Dmitry Streblechenko
Guest
 
Posts: n/a
Default Re: How to add Custom Header to Mail Item

Your code does not set the MAPI property type:

PT_STRING8 = 0x001E
....
int i = sitem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
"x-test-header");
i = i | PT_STRING8;

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

"racni" <racniro@gmail.com> wrote in message
news:1144070100.701392.12360@i40g2000cwc.googlegroups.com...
> I can not add the custom headers. It runs without giving any errors.
> But it did not change the header. If is some thing wrong with my C#
> code
>
>
>
> Please have a look at following code
>
>
>
> "x-test-header" header is not added to the email
>
>
>
>
>
> 1 Type t = Type.GetTypeFromProgID("Redemption.SafeMailItem");
>
>
> 2 Redemption.SafeMailItem sitem = (Redemption.SafeMailItem)
> Activator.CreateInstance(t);
>
> 3 sitem.Item = this.myMailItem;
>
> 4 int i =
> sitem.GetIDsFromNames("{00020386-0000-0000-C000-000000000046}",
> "x-test-header");
>
> 5 sitem.set_Fields(i,"hello");
>
> 6 SetPropValue(sitem, "Subject", "Testing Redemption");
>
> 7 sitem.Send();
>
>
>
>
>
> Please see the line number 4 . I m not sure abut it , because in the
> vb6 code it is the 8 bit string as to my knowledge . But I do not know
> the logic behind it . so how we are going to deal with this in c#.
>
>
>
> Can you help me regarding this
>
>
>
> This is the method I used for the change the subject field
>
>
>
> private static void SetPropValue(object item, string
> propertyName,
>
> object propertyValue)
>
> {
>
> try
>
> {
>
> object[] args = new Object[1];
>
> args[0] = propertyValue;
>
> Type type = item.GetType();
>
> type.InvokeMember(
>
> propertyName,
>
> BindingFlags.Public |
> BindingFlags.SetField |
>
> BindingFlags.SetProperty,
>
> null,
>
> item,
>
> args);
>
> }
>
> catch (SystemException ex)
>
> {
>
> Console.WriteLine(
>
> string.Format(
>
> "SetPropValue for {0} Exception:
> {1} ",
>
> propertyName, ex.Message));
>
> }
>
> return;
>
> }
>



  Reply With Quote
Old 04-04-2006, 10:36 AM   #3
racni
Guest
 
Posts: n/a
Default Re: How to add Custom Header to Mail Item


yes i have done the mistake . This is working correct

Thank you very much

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

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