You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Bertrand Guay-Paquet <be...@step.polymtl.ca> on 2012/08/28 17:56:40 UTC
JavaMail Session with Authentication
Hi,
I'm trying to setup a JavaMail session through TomEE but it's not
working and I'm running out of ideas...
Here is the configuration from conf/tomee.xml :
<Resource id="mail/mailsession" type="javax.mail.Session">
mail.smtp.host=smtp.gmail.com
mail.smtp.port=465
mail.transport.protocol=smtp
mail.smtp.auth=true
mail.smtp.user=myemail@gmail.com
password=myemailpassword
mail.from=myemail@gmail.com
mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory
mail.smtp.socketFactory.fallback=false
</Resource>
I reference this from an EJB bean like so:
@Resource(name = "mail/mailsession")
private Session mailSession;
and send emails this way:
MimeMessage message = new MimeMessage(mailSession, inputStream);
Transport.send(message);
The injection works fine, but Transport.send fails with the following
exception:
javax.mail.SendFailedException: Send failure
(javax.mail.AuthenticationFailedException: null)
Stepping in Transport.Send, I see that it can't find a password and
since mail.smtp.auth=true, it throws.
As far as I can see, I followed the instructions from
http://tomee.apache.org/configuring-javamail.html
I built a test app using javamail directly with the same parameters and
could send emails. However, I did have to create a PasswordAuthenticator
instance which I passed to the Session factory method. Maybe this is
missing in TomEE?
Regards,
Bertrand
Re: JavaMail Session with Authentication
Posted by Romain Manni-Bucau <rm...@gmail.com>.
if you want to propose a patch (you are pretty close to it ;))
here is the class to patch:
http://svn.apache.org/repos/asf/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/MailSessionFactory.java
*Romain Manni-Bucau*
*Twitter: @rmannibucau*
*Blog: http://rmannibucau.wordpress.com*
2012/8/31 Anthony Fryer <ap...@hotmail.com>
> Thanks for raising the JIRA. It would be nice to get the smtp
> authentication
> built into tomee.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/JavaMail-Session-with-Authentication-tp4657144p4657175.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: JavaMail Session with Authentication
Posted by Anthony Fryer <ap...@hotmail.com>.
Thanks for raising the JIRA. It would be nice to get the smtp authentication
built into tomee.
--
View this message in context: http://openejb.979440.n4.nabble.com/JavaMail-Session-with-Authentication-tp4657144p4657175.html
Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: JavaMail Session with Authentication
Posted by Bertrand Guay-Paquet <be...@step.polymtl.ca>.
Thanks so much Anthony! I was banging my head against the wall over this...
I used your code with a small mod to work with future versions of TomEE
or other containers where this is fixed :
@PostConstruct
public void postConstruct() {
boolean authenticate =
"true".equals(session.getProperty("mail.smtp.auth"));
if (authenticate) {
String protocol = session.getProperty("mail.transport.protocol");
String host = session.getProperty("mail.smtp.host");
String username = session.getProperty("mail.smtp.user");
URLName url = new URLName(protocol, host, -1, null, username,
null);
// Only specify the password authentication config if not
already present. This is a workaround for
// TomEE 1.0.0.
// TODO remove when TomEE properly handles mail session creation.
if (session.getPasswordAuthentication(url) == null
&& session.requestPasswordAuthentication(null, -1,
null, null, null) == null) {
String password = session.getProperty("password");
session.setPasswordAuthentication(url, new
PasswordAuthentication(
username, password));
} else {
log.warn("Did you forget to remove the JavaMail Session
authentication workaround for TomEE 1.0.0?");
}
}
}
I created a new JIRA issue TOMEE-407
On 29/08/2012 9:04 AM, Anthony Fryer wrote:
> I had the same issue and discovered that the password isn't actually used by
> openejb. I implemented a solution described here...
>
> http://openejb.979440.n4.nabble.com/javax-mail-Session-resource-and-smtp-authentication-td4322915.html
>
>
>
>
> --
> View this message in context: http://openejb.979440.n4.nabble.com/JavaMail-Session-with-Authentication-tp4657144p4657152.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
Re: JavaMail Session with Authentication
Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Thanks Anthony for helping on that area.
Was not aware about that restriction.
If you wanna move forward, maybe you could open a JIRA and push a patch.
We could commit it for you and it would be welcome.
Jean-Louis
2012/8/29 Anthony Fryer <ap...@hotmail.com>
> I had the same issue and discovered that the password isn't actually used
> by
> openejb. I implemented a solution described here...
>
>
> http://openejb.979440.n4.nabble.com/javax-mail-Session-resource-and-smtp-authentication-td4322915.html
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/JavaMail-Session-with-Authentication-tp4657144p4657152.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>
Re: JavaMail Session with Authentication
Posted by Anthony Fryer <ap...@hotmail.com>.
I had the same issue and discovered that the password isn't actually used by
openejb. I implemented a solution described here...
http://openejb.979440.n4.nabble.com/javax-mail-Session-resource-and-smtp-authentication-td4322915.html
--
View this message in context: http://openejb.979440.n4.nabble.com/JavaMail-Session-with-Authentication-tp4657144p4657152.html
Sent from the OpenEJB User mailing list archive at Nabble.com.