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());
}