请指点一下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

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

请各位大侠指点。
...全文
62 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
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的项目。

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧