try
{
MailMessage message = new MailMessage();
// 发送方
message.From = "xxx@163.com";
// 接收方
message.To = "xxx@163.com";
//主题
message.Subject = "Send Using Web Mail";
// 指定为HTML格式的内容
message.BodyFormat = MailFormat.Html;
// HTML内容 邮件内容
message.Body = "<HTML><BODY><B>Hello World!</B></BODY></HTML>";
//添加附件
// 指定附件路径.
String sFile = @"D:\down\dd.txt";
MailAttachment oAttch = new MailAttachment(sFile, MailEncoding.Base64);
message.Attachments.Add(oAttch);
// 指定SMTP服务器地址
SmtpMail.SmtpServer = "smtp.163.com";
//验证
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//登陆名
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "lwbpeter@163.com");
//登陆密码
message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "********");
SmtpMail.Send(message);
message = null;
oAttch = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
Console.Read();
}
|