. Net asynchronous Mail Bug

Source: Internet
Author: User
Tags mailmessage smtpclient

Let's take a look at the synchronous email sendingCode

Code

  Smtpclient _ smtpclient  =     New  Smtpclient ();
_ Smtpclient. Host = " Email server " ;
_ Smtpclient. Credentials = New Networkcredential ( " User Name " , " Password " );

Mailmessage message = New Mailmessage ();
Message. From = New Mailaddress ( " Hamptest@hampoo.com " , " Sender " , Encoding. getencoding ( 936 ));
Message. to. Add ( " Tianhu.jin@hampoo.com " ); // This is a correct address.
Message. to. Add ( " Dayan.qiu@hampoo.com " ); // This is a correct address.
Message. to. Add ( " Jieyuan.jin@hampoo.com " ); // This is an invalid address.
Message. Subject = " 111 " ;
Message. Body = " 222 " ;

// Synchronous Transmission
_ Smtpclient. Send (Message );

There are three Email recipients, and the third is invalid email addresses.

An exception is thrown: the email name cannot be used. Server Response: RP: rdn http://www.ipmotor.com/smtp_err.htm

However, the other two recipients still receive the email, for example:

 

Next let's take a look at asynchronous sending. The Code is as follows:

 

Code

  Smtpclient _ smtpclient  =     New Smtpclient ();
_ Smtpclient. Host = " Server address " ;
_ Smtpclient. Credentials = New Networkcredential ( " User Name " , "Password " );

Mailmessage message = New Mailmessage ();
Message. From = New Mailaddress ( " Hamptest@hampoo.com " , " Sender " , Encoding. getencoding ( 936 ));
Message. to. Add ( " Tianhu.jin@hampoo.com " ); // This is a correct address.
Message. to. Add ( " Dayan.qiu@hampoo.com " ); // This is a correct address.
Message. to. Add ( " Jieyuan.jin@hampoo.com " ); // This is an invalid address.
Message. Subject = " 111 " ;
Message. Body = " 222 " ;

// Asynchronous transmission
_ Smtpclient. sendcompleted + = New Sendcompletedeventhandler (sendcompletedcallback );
_ Smtpclient. sendasync (message, Null );

There are also three Email recipients, and the third is invalid email addresses.

After execution, the callback function can capture the exception information "the object application is not set to the object instance", but the other two recipients will not receive the email.

 

According to my personal understanding, synchronous and asynchronous operations are only executed in different ways, and the execution results are always the same, right? But obviously the results are different in sending emails,

Should it be a bug?

PS: I wanted to use it to send emails asynchronously in the project. Later, because the email address provided by the customer is not necessarily legal, I found this bug and finally had to switch

A new thread is opened to send emails synchronously in this thread.

 

 

 

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.