日期:2014-05-17  浏览次数:20462 次

Asp.net发邮件验证用户注册,当内容是纯文字时就能发出去,可加上个链接就收不到了,郁闷啊!!
如题,这个问题困扰好几天了
我这是用.net自带的Mail类写的代码,代码贴出来,还望众大虾指点一下啊!
protected void btnSendEmail_Click(object sender, EventArgs e)
{
/*--@"<a href='http://localhost:3535/NewElementWeb/Index.aspx?Code=" + authCode
+ "'>http://localhost:3535/NewElementWeb/Index.aspx?Code=" + authCode + "</a>"*--*/
try
{
string from = "justinwujian@sina.com";//发送者邮箱地址
string fromPwd = ""; //发送者邮箱密码,注,这里密码是有的,由于代码要贴出来,我就没写上去
string to = txtEmailAddress.Text; //接收者邮箱地址
string subject = "发送邮件测试"; //标题
string authCode = Guid.NewGuid().ToString(); //验证码
string sendContent = @"<a href='http://localhost:3535/NewElementWeb/Index.aspx?Code=" + authCode
+ "'>http://localhost:3535/NewElementWeb/Index.aspx?Code=" + authCode + "</a>";
MailMessage mailObj = new MailMessage(from, to);
mailObj.Subject = subject;
mailObj.Body = sendContent;
mailObj.BodyEncoding = System.Text.Encoding.UTF8;
mailObj.IsBodyHtml = true;
mailObj.Priority = MailPriority.High;
SmtpClient smtp = new SmtpClient("smtp.sina.com");
smtp.Credentials = new NetworkCredential(from, fromPwd);
smtp.Send(mailObj);
Response.Write("<script language='javascript'> alert('发送成功!')</script>");

}
catch (Exception ex)
{
Response.Write("发送邮件失败," + ex.Message.ToString());
}
}
[color=#FF0000][/color]
按照上面的代码发出去是收不到的,可要是sendContent这个变量写成一个字符串,比如,string sendContent = "测试发送邮件是否成功!";这样写反而是对的,发出去的邮件能接收到,为什么??快点来人救救我啊!!!


------解决方案--------------------
直接这样写就可以了

string sendContent = "http://localhost:3535/NewElementWeb/Index.aspx?Code=" + authCode; 

------解决方案--------------------
说不定被当作垃圾邮件处理了。
------解决方案--------------------
不加@这个看一下,我以前也是类似这样写的,都可以呀
------解决方案--------------------
C# code

string mailContent = "请到以下链接激活:<a href=" + url + ">" + url + "</a>";