using System.Web.Mail;
System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
client.Host = "smtp.163.com";//邮件服务器
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("hu0336@163.com", "429601");//发件人邮件地址,发件人邮箱密码
client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage("hu0336@163.com", "4092887@qq.com");//发件人邮箱地址,收件人邮箱
message.Subject = Label2.Text;//标题
message.Body =TextBox1.Text;//内容
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
//添加附件需将(附件先上传到服务器)
System.Net.Mail.Attachment data = new System.Net.Mail.Attachment(FileUpload1.PostedFile.FileName,
System.Net.Mime.MediaTypeNames.Application.Octet);//上传附件
message.Attachments.Add(data);
try
{
client.Send(message);
Response.Write("<script>alert('发送成功');</script>;location.href='ping.aspx'");
}
catch (Exception ex)
{
Response.Write("Send Email Failed." + ex.ToString());
}
- 本文标题: ASP.NET C#发邮件
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.
- 上一篇:html小技巧(防复制,防粘贴,屏蔽鼠标右键,
- 下一篇: 让IE中的IFrame透明