You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by metamor <mb...@kickapps.com> on 2008/07/21 23:27:29 UTC

Cannot send email using geronimo default email session

I am following the instructions in the article: Using Geronimo's Default
JavaMail Session
the snipet for web.xml is as follows:

     <resource-ref>
        <!-- Used in index.jsp -->
        <res-ref-name>mail/fooMailSession</res-ref-name>
        <res-type>javax.mail.Session</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>

geronimo-web.xml is:

<web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"
         xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"
         xmlns:gernaming="http://geronimo.apache.org/xml/ns/naming-1.2"
		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        
xsi:schemaLocation="http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1 ">

    <sys:environment>

        <sys:moduleId>
            <sys:groupId>fooCorp</sys:groupId>
            <sys:artifactId>testApp</sys:artifactId>
            <sys:version>1.0</sys:version>
            <sys:type>car</sys:type>
        </sys:moduleId>

		<sys:hidden-classes>
       		<filter>org.apache.commons.lang</filter>
       		<filter>org.apache.commons.lang.builder</filter>
       		<filter>org.apache.commons.lang.enum</filter>
       		<filter>org.apache.commons.lang.exception</filter>
       		<filter>org.apache.commons.lang.math</filter>
       		<filter>org.apache.commons.lang.time</filter>
       		<filter>org.jaxen</filter>
		</sys:hidden-classes>
    </sys:environment>
    <context-root>/foo</context-root>
    <gernaming:resource-ref>
         <!-- Used is web.xml -->
         <gernaming:ref-name>mail/fooMailSession</gernaming:ref-name>
          <!-- Default Geronimo mail session -->
         <gernaming:resource-link>mail/MailSession</gernaming:resource-link>
    </gernaming:resource-ref>

When I run the application I get the following error: 

org.apache.geronimo.common.DeploymentException: Unable to resolve resource
reference 'mail/fooMailSession' (Could not find resource 'mail/MailSession'. 
Perhaps it has not yet been configured, or your application does not have a
dependency declared for that resource module?

</web-app>

Any help will be greatly appreciated!
Thanks!
-- 
View this message in context: http://www.nabble.com/Cannot-send-email-using-geronimo-default-email-session-tp18577933s134p18577933.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Cannot send email using geronimo default email session

Posted by metamor <mb...@kickapps.com>.

Rick, thank you very much, I made the change that you suggested and it
worked.
About the sun implementation, I do not understand how it worked since I do
not have in my localhost a smtp server.
In any case thanks again for your help.
-- 
View this message in context: http://www.nabble.com/Cannot-send-email-using-geronimo-default-email-session-tp18577933s134p18617408.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Cannot send email using geronimo default email session

Posted by Rick McGuire <ri...@gmail.com>.
metamor wrote:
> I tried using the sun smtp implementation and works.
> With Geronimo I have turned on debug and I get the following error:
>
> SMTPTransport DEBUG: Connecting to server mail.foo.com:-1 for user noreply
> SMTPTransport DEBUG: Attempting plain socket connection to server
> mail.foo.com:25
> 220 *******************************
> EHLO DEV-ITLAP-017
> 250-mail.foo.com
> 250-PIPELINING
> 250-SIZE 10240000
> 250-VRFY
> 250-ETRN
> 250-AUTH LOGIN PLAIN CRAM-MD5 DIGEST-MD5
> 250 8BITMIME
> DEBUG: getProvider() returning provider protocol=smtp;
> type=javax.mail.Provider$Type@34ca4e;
> class=org.apache.geronimo.javamail.transport.smtp.SMTPTransport;
> vendor=Apache Software Foundation;version=1.0
> SMTPTransport DEBUG: Connecting to server localhost:-1 for user metamor
> SMTPTransport DEBUG: Attempting plain socket connection to server
> localhost:25
>
> So on transport.connect() it tries to connect to mail.foo.com (as it should)
> but for transport.send() it tries localhost?
>   

You are using the wrong method to send the message.  Transport.send() is 
a static method that obtains a new Transport instance from the default 
session to perform the send based on the type of address used for the 
sending.  You need to be using the sendMessage() method, which uses the 
connected transport instance to send the message.  I'm not sure I 
understand how the Sun version could be working for you, since 
Transport.send() wouldn't have any of the connection information needed 
to send the message.  If I had to guess, the message is getting sent 
because it's using an SMTP server that happens to be running on your 
host rather than the target one.  I did take a look, and the latest 
version of the Geronimo SMTP code is defaulting to port 25 if the 
inbound connection port is -1....something it didn't do correctly on the 
older releases.

Rick
> The code that I am using is very simple:
>
> InitialContext context = new InitialContext();
> Session mailSession = (Session)
> context.lookup("java:comp/env/mail/testMailSession");
> mailSession.setDebug(true);
>
> Transport transport = mailSession.getTransport("smtp");
> transport.connect("mail.foo.com", "norasdfy", "1norasdf1");
>
> MimeMessage message = new MimeMessage(mailSession);
> message.setFrom(new InternetAddress("metamor@yahoo.com"));
> message.addRecipient(Message.RecipientType.TO, new
> InternetAddress("metamor@gmail.com"));
> message.setSubject("test");
> message.setText("test");
> message.saveChanges();
>
> transport.send(message);
>
> Do you know what is wrong?
> Thanks in advance!
>
>   


Re: Cannot send email using geronimo default email session

Posted by metamor <mb...@kickapps.com>.

I tried using the sun smtp implementation and works.
With Geronimo I have turned on debug and I get the following error:

SMTPTransport DEBUG: Connecting to server mail.foo.com:-1 for user noreply
SMTPTransport DEBUG: Attempting plain socket connection to server
mail.foo.com:25
220 *******************************
EHLO DEV-ITLAP-017
250-mail.foo.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH LOGIN PLAIN CRAM-MD5 DIGEST-MD5
250 8BITMIME
DEBUG: getProvider() returning provider protocol=smtp;
type=javax.mail.Provider$Type@34ca4e;
class=org.apache.geronimo.javamail.transport.smtp.SMTPTransport;
vendor=Apache Software Foundation;version=1.0
SMTPTransport DEBUG: Connecting to server localhost:-1 for user metamor
SMTPTransport DEBUG: Attempting plain socket connection to server
localhost:25

So on transport.connect() it tries to connect to mail.foo.com (as it should)
but for transport.send() it tries localhost?

The code that I am using is very simple:

InitialContext context = new InitialContext();
Session mailSession = (Session)
context.lookup("java:comp/env/mail/testMailSession");
mailSession.setDebug(true);

Transport transport = mailSession.getTransport("smtp");
transport.connect("mail.foo.com", "norasdfy", "1norasdf1");

MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress("metamor@yahoo.com"));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress("metamor@gmail.com"));
message.setSubject("test");
message.setText("test");
message.saveChanges();

transport.send(message);

Do you know what is wrong?
Thanks in advance!

-- 
View this message in context: http://www.nabble.com/Cannot-send-email-using-geronimo-default-email-session-tp18577933s134p18614340.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Cannot send email using geronimo default email session

Posted by Rick McGuire <ri...@gmail.com>.
metamor wrote:
> Thanks, but smtps did not help. Is correct the smtp authentication code that
> I am using?
> I am sure that the credentials that I am using are correct.
> Any help will be appreciated.
>   
What happened when you tried to use smtps?  Did it fail in the same 
way?  You might try setting the session property mail.debug to true, but 
this is failing so early, that I'm not sure this will reveal any 
additional information. 

Rick

Re: Cannot send email using geronimo default email session

Posted by metamor <mb...@kickapps.com>.
Thanks, but smtps did not help. Is correct the smtp authentication code that
I am using?
I am sure that the credentials that I am using are correct.
Any help will be appreciated.
-- 
View this message in context: http://www.nabble.com/Cannot-send-email-using-geronimo-default-email-session-tp18577933s134p18598479.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Cannot send email using geronimo default email session

Posted by Rick McGuire <ri...@gmail.com>.
Does your server require an SSL connection?  The transport has connected 
ok, but has not received a response back from the server for the initial 
welcome reply.  This sort of points in the direction of perhaps needed 
to use the "smtps" protocol rather than "smtp".

Rick


metamor wrote:
> Thank you very much, your solution fixed my problem. 
> Now I have another issue, I am trying to connect to our smtp with
> authentication, this is the code that I am using:
>
> InitialContext context = new InitialContext();
> // Mail session from web.xml's resource reference
> Session mailSession = (Session)
> context.lookup("java:comp/env/mail/kickappsMailSession");
> mailSession.getProperties().put("mail.smtp.auth", "true");
>
> Transport transport = mailSession.getTransport("smtp");
> transport.connect("mail.foo.com", "norepl12", "1norep21");
>
> MimeMessage message = new MimeMessage(mailSession);
> message.setFrom(new InternetAddress("metamor@foo.com"));
> message.addRecipient(Message.RecipientType.TO, new
> InternetAddress("metamor@gmail.com"));
> message.setSubject("test");
> message.setText("test");
> message.saveChanges();
> transport.send(message);
>
> In the Transport.connect() I am getting the following error:
>
> javax.mail.MessagingException: java.net.SocketTimeoutException: Read timed
> out
> 	at
> org.apache.geronimo.javamail.transport.smtp.SMTPTransport.receiveLine(SMTPTransport.java:1796)
> 	at
> org.apache.geronimo.javamail.transport.smtp.SMTPTransport.receiveLine(SMTPTransport.java:1716)
> 	at
> org.apache.geronimo.javamail.transport.smtp.SMTPTransport.getReply(SMTPTransport.java:1726)
> 	at
> org.apache.geronimo.javamail.transport.smtp.SMTPTransport.getWelcome(SMTPTransport.java:1385)
> 	at
> org.apache.geronimo.javamail.transport.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:389)
> 	at javax.mail.Service.connect(Service.java:271)
> 	at javax.mail.Service.connect(Service.java:91)
>
> Any ideas of what is wrong now? Thanks so much for your help!
>
>   


Re: Cannot send email using geronimo default email session

Posted by metamor <mb...@kickapps.com>.
Thank you very much, your solution fixed my problem. 
Now I have another issue, I am trying to connect to our smtp with
authentication, this is the code that I am using:

InitialContext context = new InitialContext();
// Mail session from web.xml's resource reference
Session mailSession = (Session)
context.lookup("java:comp/env/mail/kickappsMailSession");
mailSession.getProperties().put("mail.smtp.auth", "true");

Transport transport = mailSession.getTransport("smtp");
transport.connect("mail.foo.com", "norepl12", "1norep21");

MimeMessage message = new MimeMessage(mailSession);
message.setFrom(new InternetAddress("metamor@foo.com"));
message.addRecipient(Message.RecipientType.TO, new
InternetAddress("metamor@gmail.com"));
message.setSubject("test");
message.setText("test");
message.saveChanges();
transport.send(message);

In the Transport.connect() I am getting the following error:

javax.mail.MessagingException: java.net.SocketTimeoutException: Read timed
out
	at
org.apache.geronimo.javamail.transport.smtp.SMTPTransport.receiveLine(SMTPTransport.java:1796)
	at
org.apache.geronimo.javamail.transport.smtp.SMTPTransport.receiveLine(SMTPTransport.java:1716)
	at
org.apache.geronimo.javamail.transport.smtp.SMTPTransport.getReply(SMTPTransport.java:1726)
	at
org.apache.geronimo.javamail.transport.smtp.SMTPTransport.getWelcome(SMTPTransport.java:1385)
	at
org.apache.geronimo.javamail.transport.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:389)
	at javax.mail.Service.connect(Service.java:271)
	at javax.mail.Service.connect(Service.java:91)

Any ideas of what is wrong now? Thanks so much for your help!

-- 
View this message in context: http://www.nabble.com/Cannot-send-email-using-geronimo-default-email-session-tp18577933s134p18593404.html
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.