For common emails, use system. net. mail class or system. web. the mail class can be processed, but in the Exchange server environment, these two classes do not work ------- at least what I have seen so far.
The process is as follows:
1. First add com reference "Microsoft CDO for Windows 2000 library ".
2. Email sending code:
CDO. Message MSG = new CDO. Message ();
String Password = "password ";
String from = "my@domain.com ";
String Server = "192.168.0.0 ";
MSG. From = from;
MSG. To = from;
MSG. Subject = "test mail ";
MSG. textbody = "test .";
CDO. iconfiguration iconfig = msg. configuration;
ADODB. fields = iconfig. fields;
Fields ["http://schemas.microsoft.com/cdo/configuration/sendusing"]. value = 2;
Fields ["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"]. value = from;
Fields ["http://schemas.microsoft.com/cdo/configuration/sendpassword"]. value = password;
Fields ["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"]. value = 1;
Fields ["http://schemas.microsoft.com/cdo/configuration/smtpserver"]. value = server;
Fields. Update ();
Try
{
MSG. Send ();
MSG = NULL;
}
Catch (exception ex)
{
Throw;
}
Among them, the five attributes of fields are the most restrictive subset of all its optional attributes, that is, these five attributes are indispensable, and other attributes include:
Http://schemas.microsoft.com/cdo/configuration/smtpaccountname
Http://schemas.microsoft.com/cdo/configuration/smtpuserreplyemailaddress
Http://schemas.microsoft.com/cdo/configuration/sendusername
And so on.
The strange thing is that MSG itself also has the fields attribute, or as referenced in the program: MSG. configuration. fields. configuration. the fields attribute does not allow you to send emails successfully (no errors or exceptions, but no emails can be received). Why.
The value of the smtpauthenticate attribute of fields is also very interesting. When it is set to 0, it indicates that verification is not required, 1 indicates basic verification, and 2 indicates NTLM verification, however, in outlook, I set the verification method to NTLM, and here I set the value to 1, which can be sent successfully.
Sendusing 2 indicates that an email is sent by the server specified by the smtpserver attribute. Therefore, if the server attribute is set, sendusing 2 is a common value.
Set the Server property to the IP address of the Exchange Server.