Hi Dan,

sorry for the long delay - can you have a look at
https://issues.apache.org/jira/browse/EMAIL-70 - this issue was fixed
for the upcoming commons-email-1.2 release.

But I still don't understand your problem fully

+) when using the appserver session are you using SMTP authentication?

Cheers,

SIegfried Goeschl



myllokunmingia wrote:
> Hi we're attempting to use a mail session provided by an application server
> with commons email 1.1 and the code below is the only way we could get
> commons email to work with the gmail smtp server when providing a session.
> If a session is not provided commons email is able to send an email using
> the gmail smtp server. Are we approaching the problem correctly? Or is there
> a way to incorporate the changes below into the code base?
>
> Thanks in advance,
> Dan
>
>             // set through server mail session cofiguration           
>             // Properties props = new Properties();           
>             //props.put("mail.smtps.auth", "true");
>             //props.put("mail.smtps.host", SMTP_HOST_NAME);
>             //props.put(Email.MAIL_TRANSPORT_PROTOCOL, "smtps");
>
>             final Session session =
> JndiUtil.lookup(Config.JNDI_MAIL_SESSION)
>
>             SimpleEmail email = new SimpleEmail() {
>
>                 @Override
>                 public void setMailSession(Session aSession) {
>                     Class clazz = getClass();
>                     try {
>                         Field field = clazz.getField("session");
>                         field.setAccessible(true);
>                         field.set(this, session);
>                     } catch (IllegalAccessException e) {
>                         throw new ActionException(e);
>                     } catch (IllegalArgumentException e) {
>                         throw new ActionException(e);
>                     } catch (NoSuchFieldException e) {
>                         throw new ActionException(e);
>                     } catch (SecurityException e) {
>                         throw new ActionException(e);
>                     }
>                 }
>
>                 @Override
>                 public Session getMailSession() throws EmailException {
>                     return session;
>                 }
>
>                 @Override
>                 public String sendMimeMessage() throws EmailException {
>                     Transport t = null;
>                     try {
>                         t = session.getTransport();
>                         if (SMTP_AUTH_USER != null && SMTP_AUTH_PWD != null)
> {
>                             t.connect(SMTP_AUTH_USER, SMTP_AUTH_PWD);
>                         } else {
>                             t.connect();
>                         }
>
>                         t.sendMessage(message, message.getAllRecipients());
>                         return message.getMessageID();
>                     } catch (NoSuchProviderException e) {
>                         throw new EmailException(e);
>                     } catch (MessagingException e) {
>                         throw new EmailException(e);
>                     } finally {
>                         if (t != null) {
>                             try {
>                                 t.close();
>                             } catch (MessagingException e) {
>                                 throw new EmailException(e);
>                             }
>                         }
>                     }
>                 }
>             };
>             email.setMsg(BODY);
>             email.addTo(TO);
>             email.setFrom(FROM);
>             email.setSubject(SUBJECT);
>             email.send(); 
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org

Reply via email to