注册 登录
编程论坛 ASP.NET技术论坛

[求助]关于发邮件的问题

重在参与 发布于 2007-03-13 16:47, 891 次点击

我做了一个发邮件的小程序,可是为什么收邮件时,邮件是在垃圾邮件里,而不是在收件箱里呢?
代码如下,请高手解达(我用的是.NET2003)
protected void AddBtn_Click(object sender, EventArgs e)
{
MailMessage mail = new MailMessage();
string to = this.toTxt.Text;//收信人
string send = this.sendTxt.Text;//发信人
string body = this.bodyTxt.Text;//标题
string subject = this.subjectTxt.Text;//正文
mail.To = to;
mail.From = send;
mail.Body = body;
mail.Subject = subject;
mail.BodyFormat = MailFormat.Text;
string file = this.attach.Value;

if (file != "")
mail.Attachments.Add(new MailAttachment(file));

this.send(mail);

alert("发送成功!");
}

/*
* 用来发送Email;
*/
private void send(MailMessage mail)
{
SmtpMail.Send(mail);
}
private void alert(string param)
{
this.Response.Write("<script language='javascript'>alert('" + param + "!!!'); </script>");
}
}

9 回复
#2
chenjin1452007-03-13 16:51


邮箱的问题?

#3
cyyu_ryh2007-03-13 16:51

肯定是你收件得保存路径弄错了。

#4
重在参与2007-03-13 16:58
是邮箱的问题吗?不是代码的问题呀?
#5
重在参与2007-03-13 19:52
没人了?哪位高手帮帮我呀
#6
小恶魔2007-03-13 20:03

MailMessage MM=new MailMessage();
MM.From=this.FormEmail.Text.ToString().Trim(); //发送方地址
MM.To=this.ToEmail.Text.ToString().Trim()+";"; //接收方地址
MM.Subject=this.Emailzt.Text.ToString().Trim(); //主题
MM.Body=this.Emailnr.Text.ToString().Trim(); //内容
//设置为需要用户验证
MM.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//设置验证用户名(把emailaddress改为你的验证用户名)
MM.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",[邮箱用户名]);
//设置验证密码(把password改为你的验证密码)
MM.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",[邮箱密码]);
//MM.Fields.Add("http://
if(this.file1.Value.ToString()=="")
{
}
else
{
MailAttachment oAttch =new MailAttachment(this.file1.Value.ToString(),MailEncoding.Base64);
MM.Attachments.Add(oAttch);
MM.Priority=MailPriority.High;
}
SmtpMail.SmtpServer="SMTP.***.com"; //邮件服务器地址
SmtpMail.Send(MM);
this.Response.Write("邮件发送成功!");

}

#7
重在参与2007-03-13 20:57
楼上的,谢谢了,好用了,可是我还有一个问题
MM.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",[邮箱用户名]);
//设置验证密码(把password改为你的验证密码)
MM.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",[邮箱密码]);
这两句后面得输入自己的邮箱名和密码,也就是说只有我的邮箱名才是发件人,换成其它就不好用了,我想要的是谁是发件人都行,那应该怎么办
#8
漯河2007-03-14 09:39
把它设置为一个变量
#9
小恶魔2007-03-14 21:01
页面放上文本控件 TextBox1和TextBox2
这2个文本控件是要输入帐号和密码的!

M.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/sendusername",'"+this.TextBox1.text+"');

MM.Fields.Add
("http://schemas.microsoft.com/cdo/configuration/sendpassword",'"+this.TextBox1.text+"');


这样写就可以了!
#10
zd1234562007-05-12 15:46
我先照着做一下看看…………
1