You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Martin Elkjær <ma...@elkjaer-it.dk> on 2009/11/20 20:45:09 UTC

Sending mails from OpenEJB

Hi,

I'm trying to send mails from google. I had a setup from a plain tomcat
install (without OpenEJB) that works. My resource looks like this :

<Resource  id="mtdMail" type="javax.mail.Session">
mail.smtp.starttls.enable="true"
mail.smtp.host="smtp.gmail.com"
mail.smtp.port="587"
mail.transport.protocol="smtps"
mail.smtp.auth="true"
mail.smtp.from="XXXXXXXXXXX"
mail.smtp.user="XXXXXXXXXXX"
password="XXXXXXX"
/>


I have a very simple mail bean:
-------------------------------------------------
@Stateless
public class MailSender implements MailSenderLocal {
@Resource
Session mtdMail;
 @Override
public void sendMail(String to, String subject, String content) {
Message msg = new MimeMessage(mtdMail);
        try {
msg.setFrom(new InternetAddress("noreply@mintraeningsdagbog.dk",
"MinTræningsDagbog.dk"));
msg.setRecipient(RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
            MimeBodyPart mbp1 = new MimeBodyPart();
            mbp1.setText(content);
            Multipart mp = new MimeMultipart();
            mp.addBodyPart(mbp1);
            msg.setContent(mp);
            Transport.send(msg);
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
}
}

---------------------------------------------------------

The exception thrown is:

DEBUG: getProvider() returning
javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun
Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:319)
at javax.mail.Service.connect(Service.java:169)
at javax.mail.Service.connect(Service.java:118)
at javax.mail.Transport.send0(Transport.java:188)
at javax.mail.Transport.send(Transport.java:118)
at
dk.elkjaerit.mtd.server.services.impl.MailSender.sendMail(MailSender.java:53)



Anyone managed to send mails from OpenEJB ?
And as I said - it's working from a plain Tomcat setup..


Best regards
Martin

Re: Sending mails from OpenEJB

Posted by David Blevins <da...@visi.com>.
On Nov 20, 2009, at 8:45 PM, Martin Elkjær wrote:

> Hi,
>
> I'm trying to send mails from google. I had a setup from a plain  
> tomcat
> install (without OpenEJB) that works. My resource looks like this :
>
> <Resource  id="mtdMail" type="javax.mail.Session">
> mail.smtp.starttls.enable="true"
> mail.smtp.host="smtp.gmail.com"
> mail.smtp.port="587"
> mail.transport.protocol="smtps"
> mail.smtp.auth="true"
> mail.smtp.from="XXXXXXXXXXX"
> mail.smtp.user="XXXXXXXXXXX"
> password="XXXXXXX"
> />

I've had a look at this email a couple times and didn't see any issues  
with the configuration.  But looking at it again it seems this might  
be an identical issue to one we saw a month or so ago -- accidentally  
quoting property values.  The java.util.Properties parser will not  
unquote the values.  Try removing them and it should work.

Quintin do you recall the context in which this came up the first  
time?  I think it was your eagle-eye that spotted it.  I seem to  
remember coming out of that situation with a gut instinct that we  
should handle the quotes universally so that situations like this  
couldn't happen without big loud and clear warnings.  Can't recall the  
details though.

-David