[转].net 发送邮件 备忘
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.163.com";
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("yuhai717", "*********");
//星号改成自己邮箱的密码
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new MailMessage("yuhai717@163.com", "treeyh@gmail.com");
message.Subject = "测试";
message.Body = @"<br /><br /><br /><br /><br /><br /><br /><br /><br />用自己写的软件发的邮件!";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
//添加附件
Attachment data = new Attachment(@"F:\图片\001.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
message.Attachments.Add(data);
try
{
client.Send(message);
ClientScript.RegisterStartupScript(this.GetType(), "key", "alert('成功')", true);// ("Email successfully send.");
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "key", "alert('失败')", true);
}
client.Host = "smtp.163.com";
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("yuhai717", "*********");
//星号改成自己邮箱的密码
client.DeliveryMethod = SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new MailMessage("yuhai717@163.com", "treeyh@gmail.com");
message.Subject = "测试";
message.Body = @"<br /><br /><br /><br /><br /><br /><br /><br /><br />用自己写的软件发的邮件!";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
//添加附件
Attachment data = new Attachment(@"F:\图片\001.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
message.Attachments.Add(data);
try
{
client.Send(message);
ClientScript.RegisterStartupScript(this.GetType(), "key", "alert('成功')", true);// ("Email successfully send.");
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(), "key", "alert('失败')", true);
}