1try
2 {
3
4 mailmessage m_message = new mailmessage ();
5 m_message.from = new mailaddress ("fuchifeng45@yahoo.com.cn ");
6 m_message.to.add (New mailaddress ("fuchifeng45@yahoo.com.cn "));
7 m_message.subject = "use. NET 2.0 to send the mail sample ";
8 m_message.body = "very simple ";
9 smtpclient m_smtpclient = new smtpclient ();
10 m_smtpclient.send (m_message );
11 console. writeline ("sent successfully! ");
12}
13 catch (exception E)
14 {
15 console. writeline (E. Message );
16}
17 console. Readline ();
Web. config or app. config
Config code
1 <? XML version = "1.0" encoding = "UTF-8"?>
2 <configuration>
3 <system.net>
4 <mailsettings>
5 <SMTP from = "fuchifeng45@yahoo.com.cn">
6 <network host = "smtp.mail.yahoo.com.cn" Password = "***" Port = "25" username = "**" defaultcredentials = "false"/> <! -- Whether to perform security check -->
7 </SMTP>
8 </mailsettings>
9 </system.net>
10 </configuration>