Link to home
Start Free TrialLog in
Avatar of S-Unit
S-UnitFlag for United Kingdom of Great Britain and Northern Ireland

asked on

C# EWS Exchange 2010 issue

Experts,

I have an issue regarding deploying (to a test server) an application that makes use of enterprise web services.
I have a mailing function that sends emails to clients based on the user that is logged into the system. However, these emails are required to go through Exchange.
This is where I am having an issue. The functionality is there, it does work, but for some reason, it uses the identity the app pool to send the email.

e.g. App pool is running as Domain\BloggsF.  

The email is getting sent as if it was from Bloggs F.

Can some one advise on

a) Why it would do this,
b) What the solution could be?

Regards
Avatar of LeeDerbyshire
LeeDerbyshire
Flag of United Kingdom of Great Britain and Northern Ireland image

Hard to say without seeing the code, but I don't see how EWS could even do that without Bloggs F actually having a mailbox in the first place, and I assume that your AppPool account doesn't have a mailbox?

What authentication methods do you have enabled on your EWS vdir on the target CAS server?
Avatar of S-Unit

ASKER

The AppPool account is running as a specific user (in this case the an administrator called Fred Bloggs) and therefore the person does have an email address (not ideal).

I've attached a Sample.cs file, which I'm using.

The code is then used like this...

var exchange = new ExchangeHelper();
            var service = exchange.InitialiseExchangeService(userEmailAddress);
            foreach (var client in clientData)
            {
                if (!string.IsNullOrEmpty(client.EmailAddress))
                {
                    try
                    {
                        data = exchange.CreateEmailAndSave(service, userEmailAddress, new List<string>() { client.EmailAddress }, null, null, subject, body, null);
                       
                    }
                    ...........

Is this likely to be an issue in the way the account on the web server
Sample.cs
I reckon the value of userEmailAddress is going to determine who the messages appear to come from, since that value is used to tell EWS which mailbox to connect to.  But I can't see anywhere in the code that it gets assigned a value.  Is there anywhere outside the parts you've already posted where it gets assigned?
Avatar of S-Unit

ASKER

Yes,

That value (email address) is coming from data that is fetched from the database (logged on user's) when the user logs on. This is then stored as static data and, as in this case, passed as a parameter in a method.
I've checked and it does have a value assigned to it. This is the thing that's puzzling me. If a value is assigned from user A, why is it that the email sent is coming from the account that the AppPool is running under.
ASKER CERTIFIED SOLUTION
Avatar of LeeDerbyshire
LeeDerbyshire
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of S-Unit

ASKER

Sorry for the late reply. I've been off work with the dreaded man flu. I'll try that and get back to you. Thanks.
No problem, I hope you feel better soon.
Avatar of S-Unit

ASKER

Sorry, I will be back at work to try this solution tomorrow.
Avatar of S-Unit

ASKER

Thanks a lot Lee. Though I haven't solved the issue, I know now why it occurs. You were pretty much bang on. The service will use the App pool credentials. More info can be found on this post

http://social.technet.microsoft.com/Forums/en-NZ/exchangesvrdevelopment/thread/bb916d27-c903-4ec4-b623-1a29078ad9ff