Hi,

i have a working setup.  first i put the mail resource in src/main/webapp/META-INF/context.xml like this
<?xml version="1.0" encoding="UTF-8"?>
<Context reloadable="true">
    <Resource id="mail/Session" name="mail/Session" auth="Container"
        type="javax.mail.Session" mail.smtp.host="mail.domain.tld"
        mail.smtp.port="465" mail.smtp.auth="true" mail.smtp.user="[email protected]"
        mail.smtp.password="smtppassword" password="smtppassword"
        mail.transport.protocol="smtp" mail.smtp.ssl.enable="true" />
</Context>

then i inject the resource like this
@Singleton
public class EmailAsync {

    // set in /src/main/webapp/META-INF/context.xml
    @Resource(name = "mail/Session")
    private Session session;

...
public void sendEmail(EmailMessage emailMessage) {
...
Message msg = new MimeMessage(session);
...
Transport.send(msg);



On 29/08/2017 13:27, Romain Manni-Bucau wrote:
Hi

what is your mail server?
can you activate the debug traces?


Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

2017-08-29 12:02 GMT+02:00 Dignesh <[email protected]>:

TomEE 7.0.2 :-


Sending email fails. javamail's Transport.send(...) function throws an
exception. For me looks like some issue with
"geronimo-javamail_1.4_mail-1.9.0-alpha-2.jar" jar.

If I add different mail.jar in lib folder the same code works fine

Attached the 2 jars and the sample code.

Can anyone help me to figure out what is the issue

Thank you,
Dignesh


/**
  *
  */
package dignesh.test;

import java.util.Date;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

/**
  * @author dgoyal
  *
  */
public class TestEmail
{

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception
    {

       Properties p = System.getProperties();

       // initialize mail properties
       p.put("mail.smtp.host", "10.96.132.189"); // email server
       p.put("mail.smtp.user", "smtpuser"); // sender's email address, used
for
                                            // connecting to email server
       p.put("mail.from", "[email protected]"); // sender's email address,
                                                  // displayed in the "from"
                                                  // field
       p.put("mail.store.protocol", "pop3");
       p.put("mail.transport.protocol", "smtp");
       p.put("mail.smtp.port", 25);

       Session session = null;

       session = Session.getInstance(p, new javax.mail.Authenticator()
       {
          @Override
          protected PasswordAuthentication getPasswordAuthentication()
          {
             return new PasswordAuthentication("smtpuser",
"smtppassword!");
          }
       });
       session.getProperties().put("mail.smtp.auth", true);

       MimeMessage msg = new MimeMessage(session);
       msg.setFrom();
       InternetAddress addressList[] = new InternetAddress[1];
       addressList[0] = new InternetAddress("[email protected]");

       msg.setRecipients(Message.RecipientType.TO, addressList);
       msg.setSubject("Test", "UTF-8");

       Multipart multiPart = new MimeMultipart();
       MimeBodyPart bodyPart = new MimeBodyPart();
       bodyPart.setText("Hello Test email", "UTF-8");
       multiPart.addBodyPart(bodyPart);

       msg.setContent(multiPart); // add the multipart to the message
       msg.setSentDate(new Date()); // fill in "date sent"
       Transport.send(msg); // off it goes...

    }

}
geronimo-javamail_1.jar
<http://tomee-openejb.979440.n4.nabble.com/file/n4682494/
geronimo-javamail_1.jar>
javax.jar
<http://tomee-openejb.979440.n4.nabble.com/file/n4682494/javax.jar>



--
View this message in context: http://tomee-openejb.979440.
n4.nabble.com/geronimo-javamail-1-4-mail-1-9-0-alpha-
2-sending-email-fails-tp4682494.html
Sent from the TomEE Dev mailing list archive at Nabble.com.


Reply via email to