请指点一下Servlet中发送Email的问题???

pcmax 2002-03-29 11:13:43
本人在局域网中配置了一个Exchange邮件服务器,想在一台Tomcat服务器上运行Servlet来发送邮件,Servlet编译没有出错。

其中一段代码如下:
//------------------------------------------------------------------------
out.println("one");
message = new MimeMessage(session);
out.println("two");
message.setFrom(new InternetAddress(from));
out.println("three");
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
out.println("four");
message.setSubject(subject);
out.println("five");
message.setText(body);
out.println("six");
Transport.send(message);
out.println("seven");
message.setSentDate(new Date());
out.println("eight");
throwSuccessMessage(out);
//------------------------------------------------------------------------

程序运行时报错如下:
//------------------------------------------------------------------------

one two three four five six javax.mail.NoSuchProviderException: smtp

//------------------------------------------------------------------------

请各位大侠指点。
...全文
10 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
pcmax 2002-03-29
to:楼上

Socket对象是哪个包里面的?
回复
pcmax 2002-03-29
Socket对象是哪个包里面的?
回复
idpmud 2002-03-29
Socket sessionSock = new Socket(strServer, nPort);
//strServer : server ip, nPort: port number
DataOutputStream outStream = new DataOutputStream(sessionSock.getOutputStream());
outStream.writeBytes("HELO" + " " + strServer + "\n");

定义这两个对象,就可以发Mail了,你试试。
回复
pcmax 2002-03-29
报错了:
//------------------------------------------------------------------
sendmail.java:20: cannot resolve symbol
symbol : class SmtpClient
location: class sendmail
SmtpClient send;
^
sendmail.java:87: cannot resolve symbol
symbol : class SmtpClient
location: class sendmail
send = new SmtpClient("mail.xyz.com");
^
2 errors
//------------------------------------------------------------------
回复
cenwenchuok 2002-03-29
PrintStream out;
SmtpClient send;

try
{
send = new SmtpClient("mail.xyz.com");
send.from(msgFrom);
send.to(msgto);

out = send.startMessage();
out.println("From: " + msgFrom);
out.println("To: " + msgTo);
out.println("Subject: " + msgSubject );

out.println("\n----------------\n");
out.println(message);
out.println("\r\n");
out.println("\n----------------\n");
out.flush();
out.close();
send.closeServer();
}
catch( IOException e )
{
return false;
}

return true;
回复
pcmax 2002-03-29
to : technofantasy(www.applevb.com)

你太厉害了。

thanks。
回复
TechnoFantasy 2002-03-29
public static void main(String[] argc){
/*try{
doPost();
}
catch (Exception e) {
}*/
Properties props = new Properties();
props.put("mail.host", "172.18.8.56");

try {

Session mailConnection = Session.getInstance(props, null);

Address bill = new InternetAddress("eddie@mail.powerise.com");
Address elliotte = new InternetAddress("pcmax@mail.powerise.com");

Message msg = new MimeMessage(mailConnection);

msg.setFrom(bill);
msg.setRecipient(Message.RecipientType.TO, elliotte);
msg.setSubject("You must comply.");
String[] lang={"i-zh-CN"};
((MimeMessage)msg).setContentLanguage(lang);
msg.setContent("Resistance is futile. 操",
"text/html");

Transport.send(((MimeMessage)msg));

}
catch (Exception e) {
e.printStackTrace();
}
}
回复
idpmud 2002-03-29
import java.net.*;
绝对没有问题的,我以前作过好多发mail的项目。
回复
发动态
发帖子
Web 开发
创建于2007-09-28

7.9w+

社区成员

Java Web 开发
申请成为版主
社区公告
暂无公告