1
MailMessage message
=
new
MailMessage();
2
message.From
=
new
MailAddress(fromMail);
3
message.To.Add(toMail);
4
message.Subject
=
mailSubject;
5![](/Images/OutliningIndicators/None.gif)
6
message.IsBodyHtml
=
true
;
7
message.Priority
=
MailPriority.High;
8![](/Images/OutliningIndicators/None.gif)
9
SmtpClient client
=
new
SmtpClient(
"
smtp.gmail.com
"
);
10
client.Port
=
587
;
11
client.EnableSsl
=
true
;
12
client.Credentials
=
new
NetworkCredential(username, pwd);
13
client.Send(message);
14
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
我这里使用的是gmail,而且用到了SSL,即client.EnableSsl = true; 其他的设置查询MSDN Mail类即可,但是因为配置不太一样,大家如果遇到问题多调试几遍,重要的是每个mail server供应商都不一样,设置大家参考网上的。