10 Replies Latest reply on Sep 26, 2005 9:27 AM by Andrew Oliver

    send Mail with a MimeMultipart-Body

    sebi ryffel Newbie

      I am trying to write a quite simple application with the JBoss-Mail-Server. I have chosen it, because I really like it's design. At the moment I am struggling with org.jboss.mail.message.Mail and javax.mail.internet.MimeMessage.

      I want to send a Multipart-Mail with the SMTPSenderMBean and therefore have to create a org.jboss.mail.message.Mail with a MimeMultipart-Body. I have tried many times...

      Does anyone know, how I can get such messages?



        • 1. Re: send Mail with a MimeMultipart-Body
          Andrew Oliver Master

          I'm not sure you can do this yet easily. You could create the mail with javamail, then turn it into a jboss mail object. I had deprioritized creating the JCA service for doing this because I did not know we had anyone interested in doing this yet. I'll move it up for M5 (too late for M4). Ivelin and Scott will be very happy.

          • 2. Re: send Mail with a MimeMultipart-Body
            sappenin Novice

            I've been trying this very same thing. If you're going to enable direct access to server via JCA, then I second moving the JCA service priority up -- I think it could be useful.

            In the meantime, I was able to haggle something together in the following fashion (for whomever is interested):

            1.) Assemble a javax.mail.Message with data (to, from, body, etc) taken from anywhere (I'm envisioning a servlet/jsp page in a webmail type system, for example).

            2.) Get a handle to the SMTPProtocolMBean, and create an org.jboss.mail.message.Mail object as follows (much of this was taken from the Fetchmail.popper class):

            String smtpProtocol = jboss.mail:name=SMTPProtocol,type=MailServices";
            SMTPProtocolMBean spro = (SMTPProtocolMBean) JBMailJMXUtil.getMBean(smtpProtocol, SMTPProtocolMBean.class);

            SMTPProtocolInstance proto = (SMTPProtocolInstance) spro.createInstance();

            MailListenerChain chain = (MailListenerChain) proto.getProperty(SMTPConstants.MAIL_LISTENER_CHAIN);

            BufferedInputStream bis = new BufferedInputStream(jMailMessage.getInputStream());
            Mail mail = Mail.create(jMailMessage.getAllHeaders(), // all the headers
            bis, // InputStream for the body
            jMailMessage.getSize(), // blocksize
            MailAddress.parseAddress(jMailMessage.getFrom()[0]), // sender
            MailAddress.parseAddressArray(jMailMessage.getAllRecipients()), // receipients
            proto); // SMTP

            log.info("JBossMailServer Message created");

            3.) This seems to work, except you have to make sure that the body of the Javamail message ends in "\r\n.\r\n". In addition, most Header values like "Content-type", "Message-ID", "User-Agent", and other headers don't seem to get populated using this method. When you send a traditional Javamail message via SMTP, these do get populated, but in the case above, I'm guessing they're not showing up because the smtp transport is never actually used (?) -- the message is dumped directly into the JBoss mail server data store.

            Anyway, I'm asking myself if this solution is any better than simply using Javamail to initiate an SMTP connection to JBMailServer, and send the message on that way.

            It would seem to be more efficient to access the JBMail Server's database directly, though (JCA?)

            • 3. Re: send Mail with a MimeMultipart-Body
              Andrew Oliver Master

              The above will probably be faster than our ultimate JCA component which will put things on the queues and process them through the proper mail listener chains, but not drastically so. However, right now you might as well just use the bound JavaMail that comes with JBoss for everything you're getting out of this. We'll give you retrying and queueing, a certain guarantee of delivery and mail server support. The above doesn't. you could pretty easily add the headers yourself to the above if you wanted.

              • 4. Re: send Mail with a MimeMultipart-Body
                sebi ryffel Newbie

                Thank you very much for your quick answers! For now i will send my Mails with JavaMail and wait for newer releases.
                Have a nice day


                • 5. Re: send Mail with a MimeMultipart-Body
                  Michael Barker Apprentice

                  This should be easier to implement once the messgae refactoring is done.

                  • 6. Re: send Mail with a MimeMultipart-Body
                    sappenin Novice

                    In reference to JCA access, I'm wondering if there is any particular rationale for using JCA over web-services. Transaction & security context are an obvious thing, but not sure if these would be vital for accessing JBM, hence allowing a WebServices interface instead (or perhaps both)?

                    Any thoughts here?


                    • 7. Re: send Mail with a MimeMultipart-Body
                      Michael Barker Apprentice

                      JCA is in process, Web Services are not. JCA and Web Services are used to solve different problems. JCA is for managed in process connectivity to the JBMail Server (or any system) where as Web Services would be for external clients.

                      That being said it is unlikely that we will implement Web Services interface (by that I mean a JAX-RPC interface) we are more likely to use something like REST which is more like WebDAV.


                      • 8. Re: send Mail with a MimeMultipart-Body
                        Andrew Oliver Master

                        I would see implementing web services access to mail as something more for the web services guys to do than for us. That would be in another scope outside of this project. As for internal functionality unless there is a compelling reason to use web services somewhere I wholly object to all forms of needless bloat so that probably means most places where we "could" use web services we may use lighter things. (not that JCA is light but "the man" wants it)

                        PS I wish this POS forum posting thingy would let me just write in the quick reply and hit submit rather than having to hit "post reply" and under a browser that a sane person would use. Even my wife (accountant) no longer uses IE because she got sick of adware and "issues"...

                        • 9. Re: send Mail with a MimeMultipart-Body
                          Nagesh Lakinepally Newbie

                          XXXX OFFTOPIC POST DELETED XXXX

                          • 10. Re: send Mail with a MimeMultipart-Body
                            Andrew Oliver Master

                            This forum is not for questions using the JavaMail bound service. Moreover hijacking a forum thread to ask your question is very naughty. Next, go to the "newbie questions" forum. Not here. Lastly, no one is going to give you a personalized reply. You must "watch" the forum (see the buttons above).