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