当前位置: 技术问答>java相关
请指点一下Servlet中发送Email的问题???
来源: 互联网 发布时间:2015-04-25
本文导语: 本人在局域网中配置了一个Exchange邮件服务器,想在一台Tomcat服务器上运行Servlet来发送邮件,Servlet编译没有出错。 其中一段代码如下: //------------------------------------------------------------------------ out.println("one"); message ...
本人在局域网中配置了一个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
//------------------------------------------------------------------------
请各位大侠指点。
其中一段代码如下:
//------------------------------------------------------------------------
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
//------------------------------------------------------------------------
请各位大侠指点。
|
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();
}
}
/*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();
}
}
|
import java.net.*;
绝对没有问题的,我以前作过好多发mail的项目。
绝对没有问题的,我以前作过好多发mail的项目。