发送邮件问题
大家好,我想请问一下,在网页里面点击按钮,就可以把文本框里面的内容自动发送到邮箱里面.
string str;
str = this.txtName1+ " </br> "+this.txtName2+ " </br> ";
MailMessage mes = new MailMessage();
mes.To= "haohao@126.com ";
mes.Subject = "祝福 ";
mes.BodyFormat=MailFormat.Text;
mes.BodyEncoding = System.Text.Encoding.GetEncoding( "GB2312 ");
mes.Body = str;
SmtpMail.Send(mes);
请问以上的代码为什么不能实现呢.应该怎么写呢.谢谢.
------解决方案--------------------我倒, 连SMPT都没设, 你用什么发啊?!
给个例子代码你
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class Mail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
MailMessage myMail = new MailMessage( "收件人 ", "发件人 ");
myMail.Subject = TextBox2.Text;
myMail.Body = TextBox3.Text;
myMail.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "220.181.12.16 ";//smpt主机IP
client.Port = 25;//SMPT主机端口
//SmtpMail.Credentials = new System.Net.NetworkCredential( "用户名 ", "密码 ");
client.Credentials = new System.Net.NetworkCredential( "用户名 ", "密码 ");
client.Send(myMail);
}
}