views:

56

answers:

3

Hello stackoverflowers!

I'm using Exchange Web Service exposed from exchange 2007 SP1 server to create emails from my application and I've encounted a problem I can't figure out.

I get this response "When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids." everytime I try to CreateItem() from a web application.

This only happens on a Windows 2003 + IIS6 when UseDefaultCredentials = True. But it's fine if I set the credentials with New System.Net.NetworkCredential("user","password"). The latter is not an option in production.

The strangest thing is that UseDefaultCredentials = True works if I run it from VS2008 on my local machine (but the exchange server is the same remote machine). What is wrong?

To make this more readable I've pasted a code example that uses Exchange WS API 1.0 here below. But it's the same problem if I use the Exchange WS directly.

    Dim serviceObj As ExchangeService = _
        New ExchangeService(ExchangeVersion.Exchange2007_SP1)
    serviceObj.UseDefaultCredentials = True
    serviceObj.Url = New Uri(serviceUrl)
    Dim message = New EmailMessage(serviceObj)
    message.Subject = "Greetings"
    message.Body = New MessageBody(BodyType.Text, "Hello World")
    message.ToRecipients.Add("[email protected]")
    message.SendAndSaveCopy()

Thankful for any thoughts.

A: 

defaultCredentials="false" shoud be false

and you can put this email Settings in web.config

<system.net>
 <mailSettings>
  <smtp deliveryMethod="Network">
   <network defaultCredentials="false" port="25" host="mail.domain.com" userName="[email protected]" password="123"/>
  </smtp>
 </mailSettings>
</system.net>
Muhammad Akhtar
Thanks for your quick reply, but I want the logged in user to use the service and not have anyone specific one specified in production.
draken
In that case you can use method what you have did but use defaultCredentials=false
Muhammad Akhtar
A: 

Is this a desktop app or a web app? If it's the latter perhaps DefaultCredentials is using the app pool identity?

What happens if you use:

System.Net.CredentialCache.DefaultCredentials

And UseDefaultCredentials as false?

Steven Robbins
DefaultCredentials can't be casted to ExchangeCredentials - I used DefaultNetworkCredentials instead. But it gave the same result. (When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids)
draken
Is it a web app or a desktop app?
Steven Robbins
It is a web app
draken
What authentication mode(s) have you got it in?
Steven Robbins
Only Windows Integrated authentication.
draken
A: 

The problem was solved by using Impersonation.

draken