[jboss-user] [JNDI and Naming] - JBoss 5.0.1 GA mail-service jndi

Ale Ale do-not-reply at jboss.com
Thu Nov 22 08:40:42 EST 2012


Ale Ale [https://community.jboss.org/people/armun] created the discussion

"JBoss 5.0.1 GA mail-service jndi"

To view the discussion, visit: https://community.jboss.org/message/777948#777948

--------------------------------------------------------------
Hi i want send a mail from localhost.
My mail-service.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: mail-service.xml 62350 2007-04-15 16:50:12Z  mailto:dimitris at jboss.org dimitris at jboss.org $ -->
<server>


  <!-- ==================================================================== -->
  <!-- Mail Connection Factory                                              -->
  <!-- ==================================================================== -->


  <mbean code="org.jboss.mail.MailService"
         name="jboss:service=Mail">
    <attribute name="JNDIName">java:/Mail</attribute>
    <attribute name="User">nobody</attribute>
    <attribute name="Password">password</attribute>
    <attribute name="Configuration">
      <!-- A test configuration -->
      <configuration>
        <!-- Change to your mail server prototocol -->
        <property name="mail.store.protocol" value="pop3"/>
        <property name="mail.transport.protocol" value="smtp"/>


        <!-- Change to the user who will receive mail  -->
        <property name="mail.user" value="nobody"/>



        <!-- Change to the mail server  -->
        <property name="mail.pop3.host" value="pop3.nosuchhost.nosuchdomain.com"/>


        <!-- Change to the SMTP gateway server -->
        <property name="mail.smtp.host" value="localhost"/>

        <!-- The mail server port -->
        <property name="mail.smtp.port" value="25"/>

        <!-- Change to the address mail will be from  -->
        <property name="mail.from" value=" mailto:nobody at nosuchhost.nosuchdomain.com nobody at nosuchhost.nosuchdomain.com"/>


        <!-- Enable debugging output from the javamail classes -->
        <property name="mail.debug" value="false"/>
      </configuration>
    </attribute>
    <depends>jboss:service=Naming</depends>
  </mbean>


</server>



my java class using JNDI java:/Mail

package it;









          import java.util.Properties;


          import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.naming.InitialContext;


import com.sun.mail.smtp.SMTPTransport;


          public class SendEmail {


            public static void main(String args[]) throws Exception {


            String host = "localhost";



            String from = "test at localhost";
            String to = " mailto:anemail at email.it anemail at email.it";


            // Get system properties
              Properties properties = System.getProperties();





            // Setup mail server


             properties.setProperty("mail.smtp.host", host);










InitialContext ctx = new InitialContext();


Session session = (Session) ctx.lookup("java:/Mail");










              // Create a default MimeMessage object.
            MimeMessage message = new MimeMessage(session);


            // Set the RFC 822 "From" header field using the
            // value of the InternetAddress.getLocalAddress method.
            message.setFrom(new InternetAddress(from));


            // Add the given addresses to the specified recipient type.
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));


            // Set the "Subject" header field.
            message.setSubject("hi..!");


            // Sets the given String as this part's content,
            // with a MIME type of "text/plain".
            message.setText("Hi ......");

            message.setContent ("<h1>Hello world</h1>", "text/html");






            Transport.send(message);
             System.out.println("Message Send.....");
            }
}

the output :


Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:/Mail' in SerialContext  [Root exception is javax.naming.NamingException: Invocation exception: Got null ComponentInvocation ]
          at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:439)
          at javax.naming.InitialContext.lookup(Unknown Source)
          at it.SendEmail.main(SendEmail.java:69)
Caused by: javax.naming.NamingException: Invocation exception: Got null ComponentInvocation 
          at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.getComponentId(GlassfishNamingManagerImpl.java:722)
          at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:639)
          at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:150)
          at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:425)
          ... 2 more


I think localhost port 25 is disabled.
If i start another server like "freeSMTP server" it sent mail.
I can configure mail-service.xml or enable port 25 at localhost?
i m only interested to send, not receive email. So i'm interested to SMTP not POP3.
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/777948#777948]

Start a new discussion in JNDI and Naming at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2083]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20121122/f419af13/attachment-0001.html 


More information about the jboss-user mailing list