今天做个发送电子邮件消息的网页,出现了些问题.现在解决了,记下来,便于以后复习,代码如下:
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Test Message";
myMessage.Body = "Hello World,from Planet Wrox!";
myMessage.From = new MailAddress("1xxxxx@qq.com", "1xxxxx");//发送者邮箱,发送者名
myMessage.To.Add(new MailAddress("2xxxxx@qq.com", "2xxxxx"));//接收者邮箱,接收者名
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage );
mySmtpClient.EnableSsl = true;
web.cofig
<system.net >
<mailSettings >
<smtp deliveryMethod ="Network" from ="1xxxxx<1xxxxx@qq.com>">//发送者名,发送者邮箱
<network host ="smtp.qq.com" userName="1xxxxx@qq.com" password ="xxxxxx" />//提供者,发送者名(与登陆用的一致也可以只用QQ帐号),登陆密码
</smtp>
</mailSettings>
</system.net>
使用QQ的邮箱就行,但是使用sina(新浪)的就不行,现在还在困惑中!