sending mail using java mail api using weblogic as webserver

Discussions

EJB design: sending mail using java mail api using weblogic as webserver

  1. We were trying to send mail using weblogic5.0.1 and we have got the following error

    this is the error message we have got. Could you please clarify/suggest/advice?



    message................

     javax.mail.NoSuchProviderException: No provider for Address
     type: rfc822
     javax.mail.NoSuchProviderException: No provider for Address
     type: rfc822
     at javax.mail.Session.getTransport(Session.java:475)
     at javax.mail.Transport.send0(Transport.java:154)
     at javax.mail.Transport.send(Transport.java:80)
     at
     SendMailBean.sendSmtp(SendMailBean.java:475
     )
     at jsp_servlet._email._compose._jspService_compose.java:164)
     at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
     at
     weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:105)
     at
     weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
     pl.java:123)
     at
     weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
     textImpl.java:742)
     at
     weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletCon
     textImpl.java:686)
     at
     weblogic.servlet.internal.ServletContextManager.invokeServlet(Servlet
     ContextManager.java:247)
     at
     weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.jav
     a:361)
     at
     weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:261)

     at
     weblogic.kernel.ExecuteThread.run(ExecuteThread.java, Compiled Code)
  2. Make sure mail.jar is in your classpath. Please post a code snippet that shows how you set up the mail session and send the message. Here's a snippet that works for me. I've doctored it up to indicate where your vars would be inserted:

                Properties props = System.getProperties();
                props.put ("mail.smtp.host", "your.smtp.host");
                Session mailSession = Session.getDefaultInstance (props, null);

                Message msg = new MimeMessage (mailSession);

                InternetAddress[] from = {
                    new InternetAddress ("email address of sender", "personal name of sender") };
                msg.setFrom (from[0]);

                msg.addRecipient (Message.RecipientType.TO,
                    new InternetAddress ("Recipient's email address", "Recipient's name"));

                msg.setSubject ("the subject");

                msg.setText ("the body of the message");
                
                // You could also use msg.setContent(..., ...);

                msg.setSentDate (new java.util.Date());

                Transport.send (msg);


  3. Use service pack 6 - it now includes mail-related properties files in it's META-INF/