jmail在2003上发送邮件不成功,但是在XP下同样的代码,同样的方法却不成功???
jmail在2003上发送邮件不成功,但是在XP下同样的代码,同样的方法却不成功???
是不是2003还需要怎么特殊配置么?
附代码:
================================
Dim JMail,MailServer,Flag
Set JMail=Server.CreateObject( "JMail.Message ")
If err Then
SendMail = False
response.Write( "false ")
err.clear
Exit Function
End if
JMail.Charset= "gb2312 " '邮件编码
JMail.silent=True
JMail.ContentType = "text/html " '邮件正文格式
MailServer = "smtp.163.com " '用来发送邮件的SMTP服务器
JMail.MailServerUserName = "user " '邮箱登录用户名
JMail.MailServerPassWord = "******** " '邮箱登录密码
JMail.MailDomain = "163.com " '域名(如果用 "name@domain.com "这样的用户名登录时,请指明domain.com),可选
JMail.AddRecipient MailtoAddress,MailtoName '收信人邮箱和收信人名称
JMail.Subject = Subject '主题
JMail.AppendHTML(MailBody)
JMail.FromName = FromName '发信人姓名
JMail.From = MailFrom '发信人Email
JMail.Priority = 3 '邮件等级,1为加急,3为普通,5为低级
Flag=JMail.Send(MailServer)
Response.write " <pre> " & JMail.log & " </pre> "
If Flag Then
SendMail=True
response.Write( "true ")
Else
SendMail=False
response.Write( "false2 ") |||||||||||||||||||||||此处显示错误
End If
JMail.Close
Set JMail=nothing
=========================================
在2003下,上面代码中显示错误信息: false2
如果在XP下,则可以发送邮件.
------解决方案--------------------我给你写了方法你试一下,希望能帮到你
public void sendEmail(String email,String content)
{
String tolistemail=email;
try
{
String title= "xxx ";
String strHost=xxx@sohu.com;
int nPort=0;
String strUserName= "xxx ";
String strPassWord= "xxx ";
String strFrom= "xxx ";
String strToList=tolistemail;
String strCCList= " ";
String strBCCList= " ";
String strSubject=title;
String strMessage=content;
//创建邮件的属性
Properties props=new Properties();
props.put( "mail.smtp.host ",strHost);
props.put( "mail.smtp.auth ", "true ");
Session MailSession=Session.getDefaultInstance(props,null);
MailSession.setDebug(true);
//创建一个消息
Message msg=new MimeMessage(MailSession);
//发件人地址
InternetAddress from=new InternetAddress(strFrom);
msg.setFrom(from);
//目标地址
if(strToList!=null&&strToList.length()> 0)
{
InternetAddress[]to={new InternetAddress(strToList)};
msg.setRecipients(Me