在web.config中设置smtp
在web.config中设置如下:
<system.net>
<mailSettings>
<smtp from="XXXXXXXX@gmail.com">
<network host="smtp.gmail.com" password="XXXXXXXXX" port="587"
userName="XXXXXXXXXXXX@gmail.com" />
</smtp>
</mailSettings>
</system.net>
程序调用如下:
System.Net.Mail.SmtpClient c = new System.Net.Mail.SmtpClient();
c.EnableSsl = true;
c.Send(msg);
msg那部分没有写,不过网上到处看的到。
如果不设置web.config的写法:
SmtpClient c = new SmtpClient("smtp.gmail.com");
c.Credentials = new NetworkCredential("XXXXXXx@gmail.com", "XXXXXXX");
c.Port = 587;
c.EnableSsl = true;
c.Send(msg);