在button控件的按钮事件里添加如下代码:
protected void Button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
MailAttachment m;
string myDir = UpFile.PostedFile.FileName; //UpFile是DropDownList控件的Id
if (myDir!="")
{
m = new MailAttachment(myDir);
mail.Attachments.Add(m);
}
mail.To = "pettome@163.com";
mail.From = "pettome@163.com";
mail.Subject = "举报";
string str = "举报人: " + TextBox1.Text + " 来自部门: " + TextBox2.Text + " OICQ为: " + TextBox3.Text + " 邮件地址为: " + TextBox4.Text + " 联系方式为: " + TextBox5.Text + " 主题为: " + TextBox6.Text + " 详细信息为: " + TextArea1.Value;
mail.Body = str;
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "pettome");
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "62791330");
SmtpMail.SmtpServer = "smtp.163.com";
SmtpMail.Send(mail);
Response.Write("发送成功!");
}
catch (Exception ex)
{
Response(ex.Message);
}
}
注意要加上这个命名空间:using System.Web.Mail;
Tags:
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。