Pregunta

I'm working on a WinForms Application that uses EWS to read mails of our Exchange Server. The Exchange is at Version 2007. I could successfully read, move, delete and send emails through EWS. I'm using Autodiscover to authenticate and select the Mailbox. The only problem is that I never get any sender e-mail address. The only thing I get is the name of the sender but no address.

This is my code so far:

Service1 = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
Service1.Credentials = new WebCredentials(Properties.Settings.Default.Username, Properties.Settings.Default.Password);
Service1.Url = new Uri(Properties.Settings.Default.Serviceurl);
EmailMessage messageAtt = EmailMessage.Bind(Service1, item.Id, new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments, ItemSchema.HasAttachments, EmailMessageSchema.IsRead));
EmailMessage messageData = (EmailMessage)item;

foreach (Attachment attachment in messageAtt.Attachments)
{ 
    String from = messageData.Sender.Address.ToString();   
}

This is what I get when I debug:

Screenshot

Can anyone give me a suggestion what I am mistaking here? Is there a Problem with what I wrote or could it even be a set up problem of the exchange Server?

¿Fue útil?

Solución

The problem seems to be the definition of the EmailMessage object:

By defining the EmailMessage with explicit conversion not all attributes are geting transfered to the new object. If you try it with the upper EmailMessage object which gets defined by the .Bind() method, it wont work either. The reason that happens is due to the PropertySet passed as 3rd parameter. The only solution I found is to create a 3rd object:

EmailMessage messageInfo = EmailMessage.Bind(useService, item.Id);

The disadvantage of this Object is, that you won't be able to see if the item has an attachement or not. Hope this helps anyone not wasing his time on a stupid mistake like that ;)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top