asp.net/c# 发送邮件

System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host
= "smtp.163.com";
client.UseDefaultCredentials
= false;
client.Credentials
= new System.Net.NetworkCredential("自已的163邮件地址", "密码");
client.DeliveryMethod
= System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message
= new System.Net.Mail.MailMessage("自已的163邮件地址", "收件人地址");
message.Subject
= "主题测试";
message.Body
= "asp.net发送邮件";
message.BodyEncoding
= System.Text.Encoding.UTF8;
message.IsBodyHtml
= true;
//添加附件需将(附件先上传到服务器)
        System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(@"UpFile\fj.rar",
System.Net.Mime.MediaTypeNames.Application.Octet);
message.Attachments.Add(data);
try
{
client.Send(message);
Response.Write(
"Email successfully send.");
}
catch (Exception ex)
{
Response.Write(
"Send Email Failed." + ex.ToString());

}

posted @ 2008-10-08 12:56  吴碧宇  阅读(567)  评论(1编辑  收藏  举报