An article in the blog originally introduced how to send an authentication Email:
Http://www.cnblogs.com/theone/archive/2004/05/10/8809.aspx. To use this method, you need to reference CDO in the project. Another solution is as follows:
Mailmessage testmail = new mailmessage ();
Testmail. From = "test@test.com ";
Testmail. To = "test@test.com ";
Testmail. Subject = "Test Remote ";
Testmail. bodyformat = mailformat. html;
Testmail. Body = "test mail ";
Testmail. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); // Basic Authentication
Testmail. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendusername", "username"); // set your username here
Testmail. Fields. Add ("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password"); // set your password here
Mailattachment mailattach = new mailattachment (@ "E: \ test. rar ");
Testmail. attachments. Add (mailattach );
Smtpmail. smtpserver. insert (0, "61.55.142.1 ");
Smtpmail. Send (testmail );
Although the three lines of code for authentication seem a bit confusing, it is quite easy to use.