vs2003
public static bool SendMail(string from, string to, string subject, string body, string smtpServer, string userName, string password, ref string result)
    
{
        MailMessage mailMsg 
= new MailMessage();
        
//设置正文格式
        mailMsg.BodyFormat = MailFormat.Html;
        
//设置收件人的邮件地址
        mailMsg.To = to;
        
//设置发送者的邮件地址
        mailMsg.From = from;
        
//设置邮件主题
        mailMsg.Subject = subject;
        
//设置邮件内容
        mailMsg.Body = body;
        
//设置支持服务器验证
        mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate""1");
        
//设置用户名
        mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", userName);
        
//设置用户密码
        mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", password);
        
try
        
{
            
//设置发送邮件服务器            
            SmtpMail.SmtpServer = smtpServer;
            
//发送邮件
            SmtpMail.Send(mailMsg);
            
return true;
        }

        
catch (Exception err)
        
{
            result 
= err.Message.ToString();
            
return false;
        }

    }

vs2005
public void SendEmail()
    
{
        System.Net.Mail.SmtpClient client 
= new System.Net.Mail.SmtpClient("smtp.163.com");
        client.UseDefaultCredentials 
= false;
        client.Credentials 
= new System.Net.NetworkCredential("from@163.com""888999");
        client.DeliveryMethod 
= SmtpDeliveryMethod.Network;
        System.Net.Mail.MailMessage message 
= new System.Net.Mail.MailMessage("from@163.com""to@gmail.com""subject ""body");
        message.BodyEncoding 
= System.Text.Encoding.UTF8;
        message.IsBodyHtml 
= true;
        client.Send(message);        
    }
posted on 2007-07-23 14:36 阿米 阅读(519) 评论(0)  编辑 收藏 网摘 所属分类: .NETWebDevelop

标题  
姓名  
主页
Email (博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
Google站内搜索
[推荐职位]上海盛大网络招聘架构师



China-pub 计算机图书网上专卖店!6.5万品种 2-8折!
近千种 9-95 新二手计算图书火热销售中!
开发者征途系统新作:《设计模式——基于C#的工程化实现及扩展》

相关文章:

相关链接: