我要用.NET(C#或ASP.NET)做一个邮件发送程序,在CSDN上看了很多关于邮件发送的解决方案,但实际上真正能实现的不多,因为都没有考虑邮件服务器的配置,我尝试过用JMAIL组件:(如下)
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
jmail.Message Jmail=new jmail.Message();
DateTime t=DateTime.Now;
String Subject=" From EMail .net";
String body="你好科学12:15";
String FromEmail="[email protected]";
String ToEmail="[email protected]";
//Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
Jmail.Silent=true;
//Jmail创建的日志,前提loging属性设置为true
Jmail.Logging=true;
//字符集,缺省为"US-ASCII"
Jmail.Charset="GB2312";
//信件的contentype. 缺省是"text/plain") : 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
Jmail.ContentType="text/html";
//添加收件人
Jmail.AddRecipient(ToEmail,"","");
Jmail.From=FromEmail;
//发件人邮件用户名
Jmail.MailServerUserName="goodtyl" ;
//发件人邮件密码
Jmail.MailServerPassWord="dearwife" ;
//设置邮件标题
Jmail.Subject=Subject;
//邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
//Jmail.AddAttachment( "c:\\test.jpg",true,null);
//邮件内容
Jmail.Body=body+t.ToString();
//Jmail发送的方法
Jmail.Send("wife",false);
Jmail.Close() ; }
catch(Exception bc)
{}
}
也尝试过用.NET自带的system.web.mail类:(如下)
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
MailMessage Message = new MailMessage();
Message.To = "[email protected]";
Message.From = "[email protected]";
Message.Subject = "aa";
Message.Body = "aaaaaa!";
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"] = "[email protected]";//发送地址;如果mm.From写了这儿可以不写这句
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"] = "[email protected]";
Message.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "goodtanweina";//验证账号:发送者邮箱账号
Message.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "dearwife"; //验证密码:发送者邮箱密码
Message.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; //验证级别0,1,2
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/languagecode"] = 0x0804;//语言代码
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "SMTP.XXX.com"; //SMTP Server try
{
SmtpMail.SmtpServer = "wife";
SmtpMail.Send(Message);
}
catch(System.Web.HttpException ehttp)
{
TextBox1.Text = ehttp.Message + "\n" + ehttp.ToString();
}
}
catch(Exception eee)
{
this.Response.Write(eee.ToString());
}
}
以上代码运行都不报错,但实际上不能正确的发送邮件
我分析了原因,我采用的是WIN2000默认的SMTP邮件服务器,设置也很简单,估计是这个邮件服务器功能太弱,惟一运行成功的几次是偶尔可以把邮件发到hotmail里面去,求高手指点,详细说明一下采用什么的邮件服务器,如何配置,能解决上面的问题!谢谢!!!!!
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
jmail.Message Jmail=new jmail.Message();
DateTime t=DateTime.Now;
String Subject=" From EMail .net";
String body="你好科学12:15";
String FromEmail="[email protected]";
String ToEmail="[email protected]";
//Silent属性:如果设置为true,JMail不会抛出例外错误. JMail. Send( () 会根据操作结果返回true或false
Jmail.Silent=true;
//Jmail创建的日志,前提loging属性设置为true
Jmail.Logging=true;
//字符集,缺省为"US-ASCII"
Jmail.Charset="GB2312";
//信件的contentype. 缺省是"text/plain") : 字符串如果你以HTML格式发送邮件, 改为"text/html"即可。
Jmail.ContentType="text/html";
//添加收件人
Jmail.AddRecipient(ToEmail,"","");
Jmail.From=FromEmail;
//发件人邮件用户名
Jmail.MailServerUserName="goodtyl" ;
//发件人邮件密码
Jmail.MailServerPassWord="dearwife" ;
//设置邮件标题
Jmail.Subject=Subject;
//邮件添加附件,(多附件的话,可以再加一条Jmail.AddAttachment( "c:\\test.jpg",true,null);)就可以搞定了。[注]:加了附件,讲把上面的Jmail.ContentType="text/html";删掉。否则会在邮件里出现乱码。
//Jmail.AddAttachment( "c:\\test.jpg",true,null);
//邮件内容
Jmail.Body=body+t.ToString();
//Jmail发送的方法
Jmail.Send("wife",false);
Jmail.Close() ; }
catch(Exception bc)
{}
}
也尝试过用.NET自带的system.web.mail类:(如下)
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
MailMessage Message = new MailMessage();
Message.To = "[email protected]";
Message.From = "[email protected]";
Message.Subject = "aa";
Message.Body = "aaaaaa!";
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"] = "[email protected]";//发送地址;如果mm.From写了这儿可以不写这句
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"] = "[email protected]";
Message.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = "goodtanweina";//验证账号:发送者邮箱账号
Message.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = "dearwife"; //验证密码:发送者邮箱密码
Message.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1; //验证级别0,1,2
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/languagecode"] = 0x0804;//语言代码
//Message.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = "SMTP.XXX.com"; //SMTP Server try
{
SmtpMail.SmtpServer = "wife";
SmtpMail.Send(Message);
}
catch(System.Web.HttpException ehttp)
{
TextBox1.Text = ehttp.Message + "\n" + ehttp.ToString();
}
}
catch(Exception eee)
{
this.Response.Write(eee.ToString());
}
}
以上代码运行都不报错,但实际上不能正确的发送邮件
我分析了原因,我采用的是WIN2000默认的SMTP邮件服务器,设置也很简单,估计是这个邮件服务器功能太弱,惟一运行成功的几次是偶尔可以把邮件发到hotmail里面去,求高手指点,详细说明一下采用什么的邮件服务器,如何配置,能解决上面的问题!谢谢!!!!!
解决方案 »
- 在winform里面这样的功能如何实现
- GDI+ 怎么在指定的图片上填充指定的图片?急!要疯了!
- 关于在wen.config关于修改权限的问题...
- MS vista不理想,大家觉得NET 战略会受到什么影响,前景如何?
- 为什么我的dll.在2000的系统可以下载.在2003不能下载。请问iis如何设置
- public 修饰类的疑问?
- PB调用C#写的com组件,调用不成功
- C#中如何控制将窗体整个内容变灰?
- "请求因 HTTP 状态 401 失败:Access Denied。 "这是什么问题?
- CrystalReports(水晶报表)的版权问题
- 关于页面弹出的问题~~在线等 (100分)
- 局域网内如何拷贝文件!?
我用WIN2000默认的SMTP邮件服务器,加.NET内的system.web.mail类写出来的发送邮件的程序,只能发到hotmail这样的邮箱中去,不晓得怎么回事?是不是因为hotmail是基于http协议的原因啊?
如果能够介绍一下邮件服务器方面就好了,我专做办公OA的开发,谢谢指点!!