将activation.jar copy到你的resin下的lib目录或是设置到classpath下
解决方案 »
- 求教 JAVA中引用传递的问题?
- 表单提交后,用getParameter来获取值的问题
- js简单问题
- WEB SERVICE客户端取对象的时候出现问题
- Quartz
- servlet一道面试题
- Spring Aop 拦截 Action
- weblogic服务器启动提示错误:java.lang.ClassNotFoundException: org.apache.jasper.servlet.JspServlet.急
- 问一下该选择哪两个,为什么?
- 在使用JBuilder8+Weblogic7.02出现的问题!!!
- 我的程序連接MSSQL2000,JDBC-ODBC的問題﹗
- 谁能改改我的代码在Frame上面画个圆圈?
http://www.javaresearch.org/article/showarticle.jsp?column=2&thread=12137
package jmail;
import com.sun.mail.imap.Utility;import javax.mail.internet.*;
import javax.mail.Session;
import javax.mail.MessagingException;
import javax.mail.Message;
import javax.mail.Transport;
import javax.activation.FileDataSource;
import javax.activation.DataHandler;
import java.util.Properties;
import java.util.Date;
import java.util.ArrayList;
import java.io.UnsupportedEncodingException;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2004/12/01
* Time: 13:27:40
* To change this template use File | Settings | File Templates.
*/
public class SendJavaMail { public SendJavaMail() {
}
public static void main(String[] args){
try {
Properties properties = System.getProperties();
properties.put("mail.smtp.host","172.16.8.3");
Session sendSession = Session.getInstance(properties,null);
System.out.println(sendSession.getProperty("mail.smtp.host"));
InternetAddress[] mailTo = InternetAddress.parse("[email protected]");
Message message = new MimeMessage(sendSession);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,mailTo);
message.setSubject("This message is sent by javamail");
MimeMultipart multipart = new MimeMultipart();
MimeBodyPart bodyPart = new MimeBodyPart();
bodyPart.setContent("This is a mail with file","text/html;charset=GB2312");
multipart.addBodyPart(bodyPart);
ArrayList attachment = new ArrayList();
attachment.add(0,"picture2.jpg");
attachment.add(1,"picture3.jpg");
attachment.add(2,"picture4.jpg");
attachment.add(3,"picture5.jpg");
message.setContent(multipart);
message.setSentDate(new Date());
Transport transport = sendSession.getTransport("smtp"); transport.connect("server","","");
System.out.println(transport.toString());
transport.sendMessage(message,mailTo);
transport.close();
System.out.println("The mail has sent");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException me){
me.printStackTrace();
}
}
}