Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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
Posted 13-Nov-12 0:58am
Edited 13-Nov-12 1:33am
digimanus26.6K
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

visit here....
[^]
  Permalink  
Comments
Zoltán Zörgő at 9-Nov-13 7:04am
   
I made my visit there, but nothing useful. Please note the constraints I have mentioned in my post, especially the Exchange version and authentication method, which I can not change.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi, try to use System.Net.Mail.SmtpClient. I used the following code
This code works even in .NET 2.0 with domain credentials. Some parameters has been taken from configuration file.
string mail_server = Properties.Settings.Default.MailServer;
int mail_port = Properties.Settings.Default.MailPort;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(mail_server, mail_port);
    string smtp_login = "my_login";
    string smtp_pwd = "my_pwd";
    smtp.Credentials = new System.Net.NetworkCredential(smtp_login, smtp_pwd);
    //Creating a mail message
    System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
    message.From = new System.Net.Mail.MailAddress("my_login@my_domain.my");
    int i = 0;
    // Getting recipient list from configuration file
    if( Properties.Settings.Default.Recipients.Count > 0 ){
        foreach( string mail_addr in Properties.Settings.Default.Recipients ){
            if (mail_addr.Length > 0) message.To.Add(new System.Net.Mail.MailAddress(mail_addr));
        }
        message.Subject = "My message";
        message.Priority = System.Net.Mail.MailPriority.Normal;
        message.Body = "This is a mail body message! :)";
 
        // Adding attachments
        string[] attachments = new string[2]{"my_attachment1", "my_attachment2"};
        foreach (string attachment in attachments){
            System.Net.Mail.Attachment att = new System.Net.Mail.Attachment(attachment);
            message.Attachments.Add(att);
        }
        smtp.Send(message);
    }else{
        // No recepients error
        //...
    }
I hope this code will be helpful.
  Permalink  
v4
Comments
Zoltán Zörgő at 14-Nov-12 11:37am
   
I will check your code, but I am currently struggling with System.Net.Mail.SmtpClient, if that was not clear. And my code looks very much alike yours, except that it is configured from app.config, not code. The problem is, that the SmtpClient class tries to answer to GSSAPI not to NTLM, and I can not force it to do so. I have checked the traffic with NetworkMonitor too, and I have the feeling, that the the code in the framework has some flows.
skydger at 14-Nov-12 14:49pm
   
This is strange...
I found the similar issue with this here: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/194ddefd-2d21-4b34-b630-96852ae7d03d/
But the subject is Exchange 2007, not 2003... Bit there's no a word about Service Pack 2.
Zoltán Zörgő at 16-Nov-12 4:23am
   
Yes, I have seen that forum thread, and there is a comment confirming my situation. But that's a comment from year 2007, and we are in 2012! If I would have Exchenge 2007, I would use exchange services and not smtp.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Strange as you seem to have applied all workarounds apparently available.
I noted a small difference, though: did you try to set the "from" attribute in "smtp" tag?
<smtp deliverymethod="network" from="myaccount@my.website.com">
   <network host="myserver" port="25" defaultCredentials="false" userName="[Domain\username]" password="[password]"/>
</smtp>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 645
1 OriginalGriff 453
2 CPallini 239
3 CHill60 180
4 Peter Leow 175
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 4,898
2 Maciej Los 3,159
3 Peter Leow 3,129
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 29 Apr 2014
Copyright © CodeProject, 1999-2014
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