Exchange TransportAgent ,Message's TNEF is null , How can I get a non null TNEF ? RRS feed

  • Question

  • In my transport agent code, I will set some extend property to the message. when user receiver can view it in outlook's inbox.

    But , when mail is from Outlook or owa, TNEF is not null。   when mail is from SMTP command or custom code send mail, TNEF is null.

    Set extend property must be set EmailMessage.TNEF's property. but it is null, and it is a readonly property 

    who can tell me , How can I get a non null TNEF ? or TNEF conversion before my transport agent code.

    public class MyAgent : RoutingAgent

        public MyAgent(SmtpServer server)
            this.OnResolvedMessage += PretreatmentAgent_OnResolvedMessage;

        //....some code....

        public static void SetExtendProperties(this EmailMessage me, Dictionary<string, string> exts)
            //....the TnefPart is null when message from SMTP command....
            var tnefPart = me.TnefPart;
            if (tnefPart != null)
                TnefReader reader = new TnefReader(tnefPart.GetContentReadStream());
                TnefWriter writer = new TnefWriter(

                while (reader.ReadNextAttribute())
                    if (reader.AttributeTag == TnefAttributeTag.MapiProperties)
                        writer.StartAttribute(TnefAttributeTag.MapiProperties, TnefAttributeLevel.Message);

                        int tag;
                            // The first four bytes of the tag is must be at least 0x8000 
                            // when setting a named property, the second determines the type. 
                            // http://www.cdolive.com/cdo10.htm
                            tag = (int)0x8000001E;
                        Guid PS_PUBLIC_STRINGS = new Guid("00020329-0000-0000-C000-000000000046");

                        foreach (var ext in exts)
                            writer.StartProperty(new TnefPropertyTag(tag), PS_PUBLIC_STRINGS, ext.Key);
                            writer.WritePropertyValue(ext.Value == null ? "" : ext.Value);

    Wednesday, July 1, 2020 10:48 AM

All replies

  • Hi,

    Thanks for visiting our forum, here we mainly focus on general issues about Exchange server but your question is more related to scripting. So I'll move your thread to the dedicated forum for scripting

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thanks for your understanding and hope your question will be resolved soon.



    Joyce Shen

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Thursday, July 2, 2020 1:32 AM