geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rick McGuire <rick...@gmail.com>
Subject Re: Cannot send email using geronimo default email session
Date Wed, 23 Jul 2008 16:30:33 GMT
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!
>
>   


Mime
View raw message