第二步:修改两个TetxBox的属性(也就是ID啦)为txtTo,txtFrom,然后,双击“发送”按钮,进入后台,在private void Button1_Click(
object sender, System.EventArgs e)按钮事件中添加:
下列代码:
MailMessage mailObj = new MailMessage();
if (this.txtFrom.Text.Length>0 && this.txtTo.Text.Length>0)
{
mailObj.To=this.txtTo.Text;
mailObj.From=this.txtFrom.Text;
}
mailObj.Subject = "精采笑话"; //邮件主题
mailObj.Body = "猪!你已中毒! 哈哈 "; //邮件内容
mailObj.BodyFormat = MailFormat.Html; //邮件格式
mailObj.Priority = MailPriority.High; //邮件优先度
mailObj.Attachments.Add(new MailAttachment("c:\\swf\\000.bmp")); //附件名称,可有N多。
SmtpMail.Send(mailObj); //调用系统组件发送Mail
Response.Write("发送邮件成功!");