将activation.jar copy到你的resin下的lib目录或是设置到classpath下

解决方案 »

  1.   

    你用google查关键字:javamail+authenticator就可以找到你要的解决方案了,需要将你的用户名和密码加进去
      

  2.   

    楼上两位说的很全了,再给你个例子
    http://www.javaresearch.org/article/showarticle.jsp?column=2&thread=12137
      

  3.   

    给你一个例子。
    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();
            }
        }
    }