C # using the System. Net. Mail class to send emails is quite simple.
However, generally, mail servers require spam filtering. Therefore, you must perform POP3 verification before using the SMTP service,
However, the. NET Framework API does not support this verification function. Therefore, we recommend that you use Google's Gmail to send emails.
Send emails through Google's SMTP server.
First, you need to specify the Google SMTP server address: smtp.gmail.com
Second, enable the SSL secure connection.
Third, Google's user creden。 are required.
The following code replaces some variables with valid GMAIL accounts.
1 string user = "zhangsan"; // replace it with your GMAIL user Name
2 string password = "123456"; // replace it with your GMAIL password
3 //
4 string host = "smtp.gmail.com ";
5 //
6 string mailAddress = "zhangsan@gmail.com"; // Replace with your GMAIL account
7 string ToAddress = "zhangsan@hotmail.com"; // target email address.
8 //
9
10
11 SmtpClient smtp = new SmtpClient (host );
12 smtp. EnableSsl = true; // enable the secure connection.
13 smtp. Credentials = new NetworkCredential (user, password); // create a user credential
14 smtp. DeliveryMethod = SmtpDeliveryMethod. Network; // use Network transfer
15 // create an email
16 MailMessage message = new MailMessage (mailAddress, ToAddress, "Test", "This is a Test Message ");
17 smtp. Send (message); // Send an email
The Code has been tested completely .. Replace the preceding variables with caution .. Haha
Code: Download