Click here to Skip to main content
13,448,768 members (56,686 online)

Sending mail via Exchange Server

Zoltán Zörgő asked:

Open original thread
I am experiencing troubles sending email via our Exchange server.

Exchange version is 6.5.7654.12 (2003 SP2).
Auth support: 250-AUTH GSSAPI NTLM

I have a dedicated domain account. I am running both processes under the same account, and I want to use NTLM. The VBS code is working, the .NET 4.0 code is not: 5.7.3 Client does not have permission to submit mail to this server.

VBS code:
Const strDefaultEmailAddress = ""
Const strSender = "Nobody <>"
Const cdoNTLM = 2
Const cdoSendUsingPort = 2

Set objEmail = CreateObject("CDO.Message")
objEmail.From = strSender
objEmail.To = strDefaultEmailAddress
objEmail.Subject = "TEST!" 
objEmail.HTMLBody = "<h1>TEST</h1>"
objEmail.Configuration.Fields.Item ("") = cdoSendUsingPort
objEmail.Configuration.Fields.Item ("") = "" 
objEmail.Configuration.Fields.Item ("") = 25
objEmail.Configuration.Fields.Item ("") = cdoNTLM

Ok, these fields can be set in a System.Web.MailMessage instance, but that's obsolote, so I want to use System.Net.MailMessage, but tis one has no fields to be set.

I have tried several things.
      <smtp deliveryMethod="network">
        <network host="" port="25" defaultCredentials="true" />

Than I tried to set defaultCredentials to false, and add a NetworkCredential instance with username, password and domain specified.

And other suggestions found with google too, like:
[__i__]MyMail.Credentials = CredentialCache.DefaultNetworkCredentials.GetCredential(new Uri(string.Format("smtp://{0}",MyMail.Host)), "NTLM");
MyMail.Credentials = CredentialCache.DefaultCredentials.GetCredential(new Uri(string.Format("smtp://{0}",MyMail.Host)), "NTLM");
All raised the same exception.

What is the proper equivalent of the above vbs code in c# and .net 4? Actually I would be satisfied even with storing credentials, but I have to use the authentication models allowed by the server, changing them is not an option.

Thank you in advance.

Tags: C#, Exchange-Server, Mail


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy |
Web04 | 2.8.180318.3 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100