A few months ago, I wrote a serviceMSMQSent from the message sending GroupProgram, And there is no time for testing. If you try it today, an error is reported when you send an email. The exception is as follows:
"System. Web. httpexception: failed to access the" CDO. Message "object. ---> System. reflection. targetinvocationexception: The call Target has an exception. ---> System. runtime. interopservices. comexception (0x80040211): the email cannot be sent to the SMTP server. Transmission ErrorCode0x80040217. The server response is not available \ r \ n.--- End of the internal exception stack trace --- \ r \ n
The related code is as follows:
Smtpmail. smtpserver = smtpserver;
Mailmessage = new mailmessage ();
Mailmessage. Subject = mailsubject;
Mailmessage. From = mailfrom;
Mailmessage. bodyformat = mailformat. html;
Mailmessage. Body = mailbody;
Smtpmail. Send (mailmessage );
Will such a simple code also go wrong? I wrote one now. Webform The Code passes the test. Well. Isn't it possible to write services? Now Google To one copy Yan Xiaojun Solutions: When sending an email, exceptions may occur: failed to access the "CDO. Message" object. , Hey ... And me! After unremitting efforts, I got the following answer:
After the same process, the problem is still as old;The reason remains to be studied in person! :(
As far as I know, this smtpserver does not have a verification mechanism,WebformAlso passed, the permissions assigned by the entire system are also given, and in multiple environments (Win2000, win2003).,I did not try it. Simply find a domain account and try again. Add the following three lines of code:
Mailmessage. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ","1");
Mailmessage. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", @ "×× \ ×× ");
Mailmessage. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", "×× ");
Test result: pass! Boring....
The smtpserver does not have a verification mechanism, but the error "CDO. Message" is reported without verification? Unreasonable. modify the code again, remove the user and password, and specify the defaultSMTPThe authentication parameter is"0", The Code is as follows:
Mailmessage. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate ","0");
Test result: pass!
although the Code passes, but still do not understand, why winform email CDO. what are the default parameters for message authentication?