使用System.Net.Mail发送邮件

1、在web.config中添加system.net配置项
<?xml version="1.0"?>
<configuration>
    
<appSettings/>
    
<connectionStrings/>
    
<system.web>
    
</system.web>
    
<system.net>
        
<mailSettings>
            
<smtp deliveryMethod="Network" from="jlike@163.com">
                
<network host="smtp.163.com" userName="用户名" password="密码" port="25" defaultCredentials="false"/>
            
</smtp>
        
</mailSettings>
    
</system.net>
</configuration>
2、发送邮件代码
            MailMessage message = new MailMessage();
            message.To.Add(
"jlike@163.com");//收件人
            message.Subject = "测试System.Net.Mail";//主题
            message.Body = "正文";//正文内容
            message.IsBodyHtml = false;//内容是否是html方式

            SmtpClient smtp 
= new SmtpClient();
            smtp.Send(message); 
//发送邮件


posted on 2008-01-12 19:22  amber lee zhao  阅读(308)  评论(0编辑  收藏  举报

导航