An unexpected CDO. Message Error

Source: Internet
Author: User
Tags mailmessage
Original article: an unexpected CDO. Message Error

 

A few months ago, I wrote a program for the service to retrieve and send emails from MSMQ. I haven't had time to test the program. I tried it today and encountered an error when I sent 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. The transfer error code is 0x80040217. The server response is not available \ r \ n \ 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 immediately wrote a webform test and the Code passed the test. Well. Isn't it possible to write services? Immediately Google a solution prepared by: when sending an email, it may cause an exception: failed to access "CDO. message object, which can be sorted out in several situations... and me! After unremitting efforts, I got the following answer:

 

After the process is done, the problem is still as old as possible. The reason for this problem still needs to be studied in person! :(

 

As far as I know, this smtpserver does not have a verification mechanism, and webform has passed. The permissions assigned to the entire system have been granted, and it has been tested 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 default SMTP authentication parameter as "0". The Code is as follows:

Mailmessage. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "0 ");

 

Test result: pass!

 

Although the Code passes, I still don't quite understand why the default parameters of CDO. Message sent via winform require authentication?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.