Click here to Skip to main content

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 = "address@my.com"
Const strSender = "Nobody <ApplicationPostman-CSV@my.com>"
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 ("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailserver.my.com" 
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoNTLM
objEmail.Configuration.Fields.Update
objEmail.Send
 
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.
First:
<system.net>
    <mailSettings>
      <smtp deliveryMethod="network">
        <network host="mailserver.my.com" port="25" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>
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:
MyMail.Credentials = CredentialCache.DefaultNetworkCredentials.GetCredential(new Uri(string.Format("smtp://{0}",MyMail.Host)), "NTLM");
or
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.
 
ZorgoZ
Tags: C#, Exchange-Server, mailing

Preview



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.
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 | Mobile
Web01 | 2.8.140415.2 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid