用Ecilipse开发Email的问题?
我有JB2006写了一个发Email的程序,在JB运行没有问题,但是我将代码复制到Eclipse就总是报错:
Servlet ServerEmail is not available
description The requested resource (Servlet ServerEmail is not available) is not available.
程序代码是:
String smtpServer="smtp.126.com ";
String emailTo=request.getParameter("txtto");
String fromEmail=request.getParameter("txtfrom");
String subject=request.getParameter("txtsubject");
String body=request.getParameter("txtmessage");
out.println("email is sent frish"+ smtpServer );
try
{
/* 设置发送邮件参数 */
Properties props=new Properties();
props.put("mail.transport.protocol","smtp");
props.put("mail.smtp.host",smtpServer);
props.put("mail.smtp.port","25");
props.put("mail.smtp.auth", "true"); //如果smtp服务器要求验证需使用该语句
System.setProperty( "mail.mime.charset", "gbk" ); //邮件编码设置
/* 创建用户认证对象, 如果smtp服务器需要验证则使用该对象 */
MyAuthenticator auth = new MyAuthenticator("apple","444444");
/* 获取邮件操作会话 */
Session mailsession=Session.getDefaultInstance(props,auth);
/* 构建邮件对象 */
MimeMessage msg=new MimeMessage(mailsession);
/* 设置邮件发送者 */
msg.setFrom(new InternetAddress(fromEmail));
/* 设置收件人 */
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(emailTo));
//msg.setRecipients(Message.RecipientType.CC,"swpnik@gmail.com");
/* 设置邮件发送日期 */
msg.setSentDate(new Date(System.currentTimeMillis()));
/* 设置邮件主体 */
msg.setSubject(subject,"GBK");
/* 设置邮件主体内容 */
msg.setText(body,"GBK");
/* 发送邮件 */
// Transport transport = mailsession.getTransport("smtp");
/*
//可用如下方式来提供SMTP服务器需要的用户名与密码
transport.connect(smtpServer,"accp_developer","effort");
*/
Transport.send(msg);
/* 将邮件内容显示在屏幕上 */
msg.writeTo(System.out);
out.println("邮件已成功发送到 " + emailTo);
}
catch(Exception e)
{
out.println(e);
out.println("error is appliaction");
}
out.close();
}
private class MyAuthenticator extends Authenticator{
private PasswordAuthentication pwAuth;
public MyAuthenticator(String user, String passwd)
{
pwAuth = new PasswordAuthentication(user, passwd);
}
protected PasswordAuthentication getPasswordAuthentication()
{
return pwAuth;
}
}
========================================
是不在Eclipse同JB不一样?
问题在那里?