我的环境是winserver2003+vs2003,公司内网无防火墙,只有360杀毒软件一款
jmail安装了,该引用的也引用了,相关代码如下:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using jmail;
using System.Web.Util;
using System.Web.Mail; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } public bool SendMail()
{
#region 发送邮件
jmail.Message Jmail = new jmail.Message(); //是有关邮件的对象 //string strSubject = "Hello"; //主题 //string strBody = "你好哇!!";//内容 //string strFromEmail = "[email protected]"; //邮件原地址 //string strToEmail = "[email protected]"; //收件人邮件地址
Jmail.Silent = false;//是否抛出异常false会抛出
Jmail.Logging = false;//创建日志
Jmail.Charset = "GB2312"; //邮件编码
Jmail.ContentType = "text/html";//格式 Jmail.AddRecipient("[email protected]", " ", " ");//收件人邮件地址 Jmail.From = "[email protected]"; //邮件原地址 Jmail.Body = "你好哇!!";//内容 Jmail.Subject = "Hello";//主题
Jmail.Priority = 1;//优先级1-5 1为最高
//Jmail.AddAttachment("c:\\",true,null); //附件 Jmail.MailServerUserName = "[email protected]";//smtp用户名 Jmail.MailServerPassWord = "990004086";//smtp密码
try
{
Jmail.Send("smtp.gmail.com", false);//发送
}
catch (Exception a)
{
Response.Write(a);
}
finally {
Jmail.Close();
} Response.Write("12111"); return true;
#endregion
}} 因为机器是server2003因此.NET中自带的mail类就无法发送邮件,因此换了jmail以为就能解决问题了,想不到仍旧不行,代码中换了N多的各种邮箱试验,全部不行,项目还在等着,急啊!!!
我看了csdn中N多的jmail的帖子,大多的解决都是换成163的smtp服务器,我特意申请了个网易的邮箱,换了163的smtp也仍旧不行,永远写着错误代码:
System.Runtime.InteropServices.COMException (0x8000FFFF): The message was undeliverable. All servers failed to receive the message at jmail.MessageClass.Send(String mailServer, Boolean enque)
jmail安装了,该引用的也引用了,相关代码如下:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using jmail;
using System.Web.Util;
using System.Web.Mail; public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ } public bool SendMail()
{
#region 发送邮件
jmail.Message Jmail = new jmail.Message(); //是有关邮件的对象 //string strSubject = "Hello"; //主题 //string strBody = "你好哇!!";//内容 //string strFromEmail = "[email protected]"; //邮件原地址 //string strToEmail = "[email protected]"; //收件人邮件地址
Jmail.Silent = false;//是否抛出异常false会抛出
Jmail.Logging = false;//创建日志
Jmail.Charset = "GB2312"; //邮件编码
Jmail.ContentType = "text/html";//格式 Jmail.AddRecipient("[email protected]", " ", " ");//收件人邮件地址 Jmail.From = "[email protected]"; //邮件原地址 Jmail.Body = "你好哇!!";//内容 Jmail.Subject = "Hello";//主题
Jmail.Priority = 1;//优先级1-5 1为最高
//Jmail.AddAttachment("c:\\",true,null); //附件 Jmail.MailServerUserName = "[email protected]";//smtp用户名 Jmail.MailServerPassWord = "990004086";//smtp密码
try
{
Jmail.Send("smtp.gmail.com", false);//发送
}
catch (Exception a)
{
Response.Write(a);
}
finally {
Jmail.Close();
} Response.Write("12111"); return true;
#endregion
}} 因为机器是server2003因此.NET中自带的mail类就无法发送邮件,因此换了jmail以为就能解决问题了,想不到仍旧不行,代码中换了N多的各种邮箱试验,全部不行,项目还在等着,急啊!!!
我看了csdn中N多的jmail的帖子,大多的解决都是换成163的smtp服务器,我特意申请了个网易的邮箱,换了163的smtp也仍旧不行,永远写着错误代码:
System.Runtime.InteropServices.COMException (0x8000FFFF): The message was undeliverable. All servers failed to receive the message at jmail.MessageClass.Send(String mailServer, Boolean enque)
/// 注册时发送用户帐号跟密码
/// </summary>
/// <param name="receiver">用户注册邮箱</param>
/// <param name="username">用户名</param>
/// <param name="password">用户密码明文</param>
public bool Register(string receiver, string strusername, string content)
{
bool IsOK = false;
jmail.Message Jmail = new jmail.Message(); String Subject = "帐号";
String body = content;
String FromEmail = "[email protected]";
String ToEmail = receiver;
//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 = "[email protected]";
//发件人邮件密码
Jmail.MailServerPassWord = "990004086";
//设置邮件标题
Jmail.Subject = Subject;
//邮件内容
Jmail.Body = body;
//Jmail发送的方法
if (Jmail.Send("smtp.gmail.com", false))
{
IsOK = true;
}
Jmail.Close();
return IsOK;
}
我用这个行
if (Jmail.Send("smtp.gmail.com", false))
{
IsOK = true;
}
在这加个输出语句看根本没走!
给你代码 用不用随便你了
using System.Net.Mail;namespace MRMF_HR_SysNode.Information
{
public class PersonMail_zchy
{
public Int32 i = 0;
/// <summary>
/// 注册个人会员后发送邮件
/// </summary> public Int32 SendPersonMail(String personName,String personMail,String username,String password)
{
System.Net.Mail.SmtpClient client = new SmtpClient("smtp.163.com",25);
client.Timeout = 60000; client.UseDefaultCredentials = true;
client.Credentials = new System.Net.NetworkCredential("发送邮箱的账号", "密码");
client.DeliveryMethod = SmtpDeliveryMethod.Network;
MailMessage mail = new MailMessage();
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.From = new MailAddress("发送的邮箱地址", "发送者名称", System.Text.Encoding.UTF8);
mail.To.Add(new MailAddress("接收的邮箱地址","接受者名称", System.Text.Encoding.UTF8));
mail.IsBodyHtml = true; mail.Subject = "邮件标题";
mail.Body += "邮件内容" try
{
client.Send(mail);
i = 1;
}
catch (Exception)
{
i = 0;
}
return i;
}
}
}
注意检查:1、防火墙是否有限制
2、smtp的验证方式是否设置正确
现在还在用着
不过服务器不是我弄的
别人弄好了的
你代码我没有看出错
估计是服务器配置的问题
1.没装任何防火墙(系统防火墙已关闭)只有一个360关掉也不行!也没找到邮件限制问题!
2.几乎看遍了所有类似jmail代码和我的如出一辙!
加入引用以后,增加Jmail类,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using jmail;
namespace BLL
{
public class Jmail
{
public static bool SendMail(string from, string to, string subject, string body)
{
jmail.Message m = new Message();
m.Charset = "gb2312";
m.From = from;
m.Subject = subject;
m.AddRecipient(to, null, null);
m.MailServerUserName = "[email protected]";
#region password
m.MailServerPassWord = "www.svnhost.cn";
#endregion
m.ContentType = "text/html";
m.Body = body;
m.Send("smtp.163.com", false);
return true;
}
}
}
然后就可以发送Email了,如果开发机或者服务器安装了杀毒软件可能会拦截邮件发送,需要关闭杀毒软件的“邮件蠕虫........”这个选项,还有邮件服务器,需要支持SMTP功能
在 jmail.MessageClass.Send(String mailServer, Boolean enque)
在 WinCL.Email.MailSending() 位置 E:\工作资料\crm3.0\3.0\WinCL\Email.cs:行号 326}
同样的问题解决不了!如果楼主解决了,麻烦告诉我一下怎么解决的。谢谢
在 jmail.MessageClass.Send(String mailServer, Boolean enque)
在 WinCL.Email.MailSending() 位置 E:\工作资料\crm3.0\3.0\WinCL\Email.cs:行号 326}
同样的问题解决不了!如果楼主解决了,麻烦告诉我一下怎么解决的。谢谢