c#发送邮件

需要引用System.Web.Mail命名空间。引用该命名空间需要添加System.Web.Dll

MailMessage mail = new MailMessage();
    mail.BodyFormat=MailFormat.Html;
    mail.From ="some@server";
    mail.To="some@server";//多个收件人之间用分号分割
    mail.Bcc="some@server";//密送
    mail.Cc=="some@server";//抄送
    mail.Subject = "this is mail subject";
    mail.Body ="this is mail body";
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "username");
    mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "password);  
   
    System.Web.Mail.MailAttachment attachment=new MailAttachment("c:\\1.txt");
    mail.Attachments.Add(attachment);
    SmtpMail.SmtpServer = "10.2.140.100";
    SmtpMail.Send(mail);
posted on 2006-05-23 16:39  stswordman  阅读(3362)  评论(4编辑  收藏  举报