在标签中添加代码。
配置Web.config,在<configuration>标签中添加以下代码,(aaaaaaaaaa:表示发信人的邮箱号.bbbbbbbbbb:表示前面获取的授权码.端口号port:我测试25能发,而465不能发。
具体代码如下:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="nekorz &lt1018472917@qq.com&gt">
<network host="smtp.qq.com" userName="aaaaaaaaaa@qq.com" password="bbbbbbbbbb" port="25" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>
添加发送邮件代码:
MailMessage myMessage = new MailMessage()
myMessage.Subject = "Test Message"
myMessage.Body = "这是一封测试邮件."
myMessage.To.Add(new MailAddress("aaaaaaaaaa@qq.com", "昵称"))
SmtpClient mySmtpClient = new SmtpClient() try
{
mySmtpClient.Send(myMessage)
} catch (SmtpException ex)
{
}
smtp.Credentials = new System.Net.NetworkCredential改成("xxx@qq.com", "xxx")smtp.Credentials = new System.Net.NetworkCredential("xxx", "xxx")
不要@qq.com
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)