protected void Button1_Click(object sender, EventArgs e)
{
System.Net.Mail.SmtpClient client = new SmtpClient();
client.Host = "smtp.126.com";
client.UseDefaultCredentials = false;
client.Credentials = new System.Net.NetworkCredential("houdezaiwuwanglei","19841016");
client.DeliveryMethod = SmtpDeliveryMethod.Network; //指定如何发送邮件的方式
System.Net.Mail.MailMessage message = new MailMessage("******@126.com", "*************@hotmail.com");
message.Subject = "测试Ok";
message.Body = "软件发送已收到ssss!";
message.BodyEncoding = System.Text.Encoding.UTF8;
message.IsBodyHtml = true;
//添加附件
Attachment data = new Attachment(@"C:\Documents and Settings\wanglei\My Documents\My Pictures\SS.jpg", System.Net.Mime.MediaTypeNames.Application.Octet);
message.Attachments.Add(data);
try
{
client.Send(message);
Response.Write("OK");
}
catch (Exception ex)
{
throw new Exception("Send Email Failed:"+ex.ToString());
}
}
这个就可以了。你的邮件如果想灵活可以在页面上做文本框。输入想输入的。