发邮件代码那里错了??
发邮件代码那里错了??
using System.Web.Mail;
private void button6_Click(object sender, System.EventArgs e)
{
try
{
MailMessage mm=new MailMessage();
mm.BodyFormat=MailFormat.Text;
mm.To=this.textBox1.Text.Trim();
mm.From=this.textBox2.Text.Trim();
mm.Subject=this.textBox4.Text.Trim();
mm.Body=this.textBox3.Text.Trim();
SmtpMail.SmtpServer="smtp.163.com";
SmtpMail.Send(mm);
MessageBox.Show("ok");
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
问题点数:10、回复次数:12Top
1 楼fsdy2000(乡愁)回复于 2005-07-04 10:20:58 得分 0
出什么问题了。使用smtp.163.com,好像要用户信息Top
2 楼zjh135(aaa)回复于 2005-07-04 12:12:53 得分 0
大家可以考去修改一下运行一下,也不知用户名与密码加在那里??Top
3 楼fsdy2000(乡愁)回复于 2005-07-04 15:43:35 得分 10
MailMessage mail = new MailMessage();
mail.To = "me@163.com";
mail.From = "you@163.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "AlleNny"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "Password"); //set your password here
SmtpMail.SmtpServer = "smtp.163.com"; //your real server goes here
SmtpMail.Send( mail );Top
4 楼fsdy2000(乡愁)回复于 2005-07-04 15:49:13 得分 0
另外:
1、使用socket进行smtp编程。发送User和PWD等命令
2、使用CDO的MessageClass
Top
5 楼fsdy2000(乡愁)回复于 2005-07-04 15:51:22 得分 0
使用Socket发送:
“EHLO ”+ mailserver + enter;
"AUTH LOGIN “+Base64Encode(username) + enter;
+Base64Encode(password) + enter;Top
6 楼zjh135(aaa)回复于 2005-07-05 08:58:48 得分 0
还是不能发送,什么CDO的MESSAGE错误!!Top
7 楼wholdbird(老来学IT)回复于 2005-07-05 09:16:29 得分 0
要加上楼上fsdy2000说的身份验证,同是你的正文编码类型要设好,不然收到的中文会是乱码Top
8 楼fsdy2000(乡愁)回复于 2005-07-05 09:27:04 得分 0
我提供了三种方法,你就使用SmtpMail/MailMessage即可。Top
9 楼zjh135(aaa)回复于 2005-07-05 11:22:47 得分 0
大家能不能给点代码啊!!Top
10 楼fsdy2000(乡愁)回复于 2005-07-05 13:43:37 得分 0
不是已经给你代码了吗?在你的代码中加入:
mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "用户名"); mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "密码");Top
11 楼zjh135(aaa)回复于 2005-07-08 11:25:34 得分 0
乡愁你好:
add的第一个参数是什么意思?(如("http://schemas.microsoft.com/cdo/configuration/sendusername"), 必须要这样吗?我知其然不知其所以然呢??
回答了我结分了Top
12 楼fsdy2000(乡愁)回复于 2005-07-11 09:24:56 得分 0
Fields属性是1.1版本中新增的,允许访问根本的(underlying) CDO.Message 域。第一个参数即是所访问的域,第二个参数是设定的值。Top




