Exchange Server TechCenter >
Exchange Server Forums
>
Development
>
EWS Managed API setting Internet Message Headers
EWS Managed API setting Internet Message Headers
- I am trying to create an application that will add email messages into my Exchange server, but I am running into issues setting headers on the email message I am creating. My code is as follows:
ExchangeService es = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
es.UseDefaultCredentials = false;
es.Credentials = new WebCredentials("Administrator", "1234567890", "xyz.com");
es.Url = new Uri("https://omega.xyz.com/EWS/exchange.asmx");
EmailMessage em = new EmailMessage(es);
em.SetExtendedProperty(new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "Received", MapiPropertyType.String), ": by 10.204.65.207 with SMTP id k15cs110962bki;\n Wed, 2 Sep 2009 13:26:19 -0700 (PDT)");
em.Subject = "TESTING";
em.From = "dave@xyz.com";
em.ToRecipients.Add("test@xyz.com");
em.Save(WellKnownFolderName.Inbox);
For now I'm just using a sample header I have taken from a real email message, to test the code out. Once the email is saved, I am able to view it in outlook, but when I view the message properties, the Internet Headers field is blank.
The aim behind this application is to pull email messages from various other accounts and insert them into my exchange server. There are other applications out there that do this and submit to Exchange via SMTP, but this results in the headers being changed, and I wish to keep the headers intact in my Exchange server. My current work-around to this is running Outlook on my server, obviously this is far from optimal.
www.dlpwd.co.uk
All Replies
- Let me get it clarified... I believe you set the InternetHeaders and its values, but this Internet Headers fields values are blank?
I suspect that, once you have the names of the headers, you can try make another call back to fetch their values. Can you try this code sample from Stephen Griffin's blogpost, http://blogs.msdn.com/stephen_griffin/archive/2007/02/09/exchange-web-services-and-internet-message-headers.aspx and let me know whether this helps you?
DeVa, M.S., {MSFT} - Thanks for the reply, I am using the Managed API, so the code would be different to that used in the blog post you linked. Also, I am trying to set the headers, not retrieve existing ones. The basic aim is to collect an email message via the POP3 protocol, and then transfer that message into Exchange (I do not wish to submit it using SMTP, as this will alter the headers). I am creating a new instance of the EmailMessage class, but am unable to set any headers on it.
www.dlpwd.co.uk - Hi DaveLegg,
did you eventually manage to set the message headers with the Exchanged Managed API?
- No, I'm still trying to find a solution
www.dlpwd.co.uk - Too bad, I tried to figure it out for some time now...
A litte OT: How did you change the type of the message so it won't appear as draft? Did you use the extended property (PR_MESSAGE_FLAGS) or do you have a better solution? - So it's not possible then? Any word on this from a developer?
- Hi again,
this may be interesting (specially for you DaveLegg, since noone else seems to care ;)):
I found that the internet message headers ARE in fact stored (when using extended properties) but for a reason I can't explain, they're not shown. Funny thing though: Once you update the MimeContent of the message -> voila -> all the headers are shown ^^
So to show the internet message headers write something like:
EmailMessage msg = EmailMessage.Bind(m_exchangeService, messageId); PropertySet props= new PropertySet(Microsoft.Exchange.WebServices.Data.EmailMessageSchema.MimeContent); msg.Load(myPropertySet2); msg.MimeContent.Content = msg.MimeContent.Content; msg.Update(ConflictResolutionMode.AutoResolve);
and the headers will show in outlook and ews.
- Thanks, I will give that a go.
www.dlpwd.co.uk


