新建一个ASP.NET Web应用程序
添加两个命名空间:
using System.Web.Mail;
using System.Text;
添加按钮源代码:
if(this.MailTo.Text=="")
{
Response.Write("<script>window.alert('请填写收件人地址!');</script>");
}else
if(this.MailFrom.Text=="")
{
Response.Write("<script>window.alert('请填写发件人地址!');</script>");
}else
if(MailTitle.Text=="")
{
Response.Write("<script>window.alert('请填写标题!');</script>");
}else
if(this.MailContent.Text=="")
{
Response.Write("<script>window.alert('请填写内容!');</script>");
}
else
{
MailMessage MailObj=new MailMessage();
if(MailTo.Text.Length>0&&MailFrom.Text.Length>0&&MailTitle.Text.Length>0)
{
MailObj.To=MailTo.Text;
MailObj.From=MailFrom.Text;
}
MailObj.Subject=MailTitle.Text; //邮件主题
MailObj.Body=this.MailContent.Text; //邮件内容
MailObj.BodyFormat = MailFormat.Html; //邮件格式
if(levelList.Rows==1)
MailObj.Priority=MailPriority.High;
if(levelList.Rows==3)
MailObj.Priority=MailPriority.Low;
if(levelList.Rows==2)
MailObj.Priority=MailPriority.Normal; //邮件优先度
if(FileUrl.PostedFile.FileName!="")
{
string FileName=FileUrl.PostedFile.FileName;
MailObj.Attachments.Add(new MailAttachment(FileName));
SmtpMail.Send(MailObj); //调用系统组件发送Mail
Response.Write("<script>window.alert('发送邮件成功!');</script>");
}
else
{
SmtpMail.Send(MailObj); //调用系统组件发送Mail
Response.Write("<script>window.alert('发送邮件成功!');</script>");
}
}
更多信息请访问:http://211.68.247.95:81/03soft/index.aspx