I have fixed it using JavaMail API:public void sendMail(
String from,
String[] to,
String[] bcc,
String subject,
String body,
String host
)
{
Properties props = new Properties();
props.put("mail.smtp.host", host); Session session = Session.getInstance(props, null);
try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom( new InternetAddress(from) ); InternetAddress[] address = new InternetAddress[to.length];
for (int i = 0; i < to.length; ++i) {
address[i] = new InternetAddress(to[i]);
}
msg.setRecipients(Message.RecipientType.TO, address); if (bcc != null) {
address = new InternetAddress[bcc.length];
for (int i = 0; i < bcc.length; ++i) {
address[i] = new InternetAddress(bcc[i]);
}
msg.setRecipients(Message.RecipientType.BCC, address);
}
msg.setSubject(subject);
msg.setText(body);
msg.setSentDate( new Date() );
Transport.send(msg);
}
catch (Exception ex) {
ex.printStackTrace(System.err);
}
}regards!
String from,
String[] to,
String[] bcc,
String subject,
String body,
String host
)
{
Properties props = new Properties();
props.put("mail.smtp.host", host); Session session = Session.getInstance(props, null);
try {
MimeMessage msg = new MimeMessage(session);
msg.setFrom( new InternetAddress(from) ); InternetAddress[] address = new InternetAddress[to.length];
for (int i = 0; i < to.length; ++i) {
address[i] = new InternetAddress(to[i]);
}
msg.setRecipients(Message.RecipientType.TO, address); if (bcc != null) {
address = new InternetAddress[bcc.length];
for (int i = 0; i < bcc.length; ++i) {
address[i] = new InternetAddress(bcc[i]);
}
msg.setRecipients(Message.RecipientType.BCC, address);
}
msg.setSubject(subject);
msg.setText(body);
msg.setSentDate( new Date() );
Transport.send(msg);
}
catch (Exception ex) {
ex.printStackTrace(System.err);
}
}regards!
解决方案 »
- No Hibernate Session bound to thread, and configuration does not allow creation
- Spring 不解析JAR包 !!急
- 求救:Tomcat不能启动
- 请问应用服务器运行的业务逻辑层都是WEB服务来的吗?
- Hibernate小白问题,高分求解!2个表多字段连接
- weblogic更新了类文件无效,删除了该类文件仍可访问
- 为什么我的JB 9里支持GBK码而eclipse里却不支持呢?
- 帮我看看这个布署是错误什么原因啊!急!!! (LINUX+WEBLOG8.1sp2)
- spring ioc 解耦
- 类对象的增强???是指什么?
- 100分,不够再加,高手救我呀
- 关于实体bean关联错误
import javax.mail.*;
import java.io.*;
import javax.mail.internet.*;
import javax.activation.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class Email {
public Email() {
super();
}
public void sendmail(String smtp, String from, String to, String subject, String body){
Session session;
MimeMessage message;
Properties props = System.getProperties();
props.put("mail.smtp.host", smtp);
session = Session.getInstance(props, null);
message = new MimeMessage(session);
try{
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(subject);
message.setText(body);
Transport transport = session.getTransport("smtp");
transport.send(message);
System.out.println("send successfully");
}catch(MessagingException e){
e.getMessage();
}
}}