
jmail发送邮件的实例代码网上很多.但是有些细节如果不配置好,发送失败的可能性很大.
首先说明一下jmail安装配置步骤:
    1. JMail 下载地址
     http://www.xunmeinet.com/doc/jmail43.rar
2.安装
本人在Windows 2003下面配置,其它系统还没有测试。安装到目录比如: C:\Program Files\Dimac\w3JMail4\jmail.dll
然后还需要把jmail.dll复制到系统目录,比如C:\WINDOWS\system32
再运行:regsvr32 jmail.dll
这样才算把jmail安装好了.
3.如果出现标题显示的错误,检查下列内容.
(1)、用户名和密码
    在代码里要写上 
smtpUser ="用户名" 
smtpPass="密码" 
或是 
objMail.Send("用户名:密码@server.net") 
要写发送端连接的邮件服务器和进入邮件服务器的用户名和密码。用户名和密码一定要存在于服务器上且正确。而且好象用户名和密码最好不要带下划线。
    (2)、.防火墙阻止了网络通讯或网络故障 
有可能防火墙会认为这是蠕虫导致的狂发邮件的情况,所以会禁止群发邮件。
所以检查防火墙的设置就可能会发现。
(3).jmail组件权限不够
(4).邮件服务器故障
(5)测试用的邮件服务器比如:smtp.163.com可能把你列入黑名单,换个邮件服务器发。尽量不要不停发邮件。
    在 .NET 中使用 Jmail 需要如下设置:
1、安装jmail;
2、找到jmail.dll;
3、注册该组件Jmail.dll,作法是将jmail.dll文件拷贝到system32目录下,再运行命令“regsvr32 jmail.dll”(不包括引号),卸载可运行“regsvr32 /u jmail.dll”;
4、执行Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Bin\ildasm.exe(可使用Visual Studio .Net 2003 命令提示),
格式如下:tlbimp c:\Program Files\Dimac\w3JMail4\jmail.dll /out:MyJmail.dll /namespace:MyJmail
生成MyJmail.dll后,将它引用至项目中
事例代码:
<%
/********************************************************************************
   JMail 下载地址
http://hbdx3.skycn.com/down/w3JMail43Personal.exe
  
安装之后把jmail.dll放到系统目录
然后运行:regsvr32 jmail.dll
********************************************************************************/
//SMTP Server config
var val_sSMTPServer = "smtp.126.com";
var mailFrom = "test@126.com";//邮箱地址
var smtpUser = "username";//邮箱用户名
var smtpPass = "******";//邮箱密码
function Rw(dat)
{
   Response.Write(dat + '\r\n');
   return;
}
function Rf(dat)
{
   return Request.Form(dat)();
} 
function JMailSend(fromName,formMail,toMail,mailSubject,mailBody)
{
   var objMail = new ActiveXObject( "JMail.Message" );
    var subject = mailSubject;
    var body = mailBody;
    var mail = toMail;
    objMail.Logging = true;
    objMail.Charset = "UTF-8";
    objMail.Priority = 3;
    objMail.ContentType = "text/html";
    objMail.From = formMail;
    objMail.FromName = fromName;
    objMail.AddRecipient( mail );
    objMail.Subject = subject;
    objMail.Body = body;
    objMail.MailServerUserName = smtpUser;
    objMail.MailServerPassword = smtpPass;
    objMail.Send( val_sSMTPServer ); 
   objMail.Close();
}
/*
碰到这种情况说明网易把IP列入黑名单需要换smtp服务器
The message was undeliverable. All servers failed to receive the message
ClientLogging enabled: Client Remote Address: 127.0.0.1
.execute()
{
Trying server mail:smtp.163.com
<- 220 163.com Anti-spam GT for Coremail System (163com[20050206])
-> EHLO linjin10-sj78xi
<- 250-mail
250-PIPELINING
250-AUTH LOGIN PLAIN
250-AUTH=LOGIN PLAIN
250 8BITMIME
-> AUTH LOGIN
Sending authentication data..
<- 550 用户被锁定
Authentication failed.
smtp.163.com failed..
No socket for server. ConnectToServer()
1 of 1 servers failed
}