C#邮件客户端发送邮件失败问题
我看了MSDN上的例子觉得没错,但为什么发不出去?请达人们帮帮忙啊,谢谢了
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Net.Mail;
using System.Web.Security;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btSubmit_Click(object sender, EventArgs e)
{
//设置MailMessage类的to属性所需的MailAddress
MailAddress toAddress = new MailAddress(this.tbReceiver.Text);
//设置MailMessage类的from属性所需的MailAddress
MailAddress fromAddress = new MailAddress(this.tbSender.Text);
//新建一个MailMessage类实例
MailMessage message = new MailMessage(fromAddress, toAddress);
//设置这个实例的Subject属性
message.Subject = this.tbSubject.Text;
//设置这个实例的Body属性
message.Body = this.tbMessage.Text;
//添加附件
//获得文件
HttpPostedFile postedFile = file.PostedFile;
//当有附件时
if (postedFile.ContentLength != 0)
{
//声明一个Attachment类实例
Attachment data = new Attachment(postedFile.FileName);
message.Attachments.Add(data);
}
//设置正文格式
if (rblFormat.SelectedItem.Text == "纯文本格式 ")
message.IsBodyHtml = false;
else
message.IsBodyHtml = true;
//添加抄送地址
if (this.tbCc.Text != " ")
{
MailAddress ccAddress = new MailAddress(this.tbCc.Text);
message.CC.Add(ccAddress);
}
//添加暗送地址
if (this.tbBcc.Text != " ")
{
MailAddress bccAddress = new MailAddress(this.tbBcc.Text);
message.Bcc.Add(bccAddress);
}
//新建一个SmtpClient类的实例
SmtpClient client = new SmtpClient();
//设置在本机smtp服务器中绑定的ip地址,本例为本机ip地址
client.Host = "192.168.1.103 ";
//smtp端口,默认为25
client.Port = 25;
//发送
client.Send(message);
//发送完毕后提示
Response.Write( " <script language= 'javascript '> alert( '发送成功 ') </script> ");
}
}
[解决办法]
提交的服务器应该包括的你FROM
[解决办法]
http://www.cnblogs.com/yyw84/archive/2006/05/17/402381.aspx