Note that there are some explanatory texts on larger screens.

plurals
  1. POSending email from a java stateless EJB (Java EE-6)
    text
    copied!<p>I want to send an email ussing an EJB but i the only thing i get in return in this exception:</p> <pre><code>java.lang.RuntimeException: javax.mail.AuthenticationFailedException: failed to connect, no password specified? </code></pre> <p>This is how my EJB looks like:</p> <pre><code>@Stateless(name = "ejbs/EmailServiceEJB") public class EmailServiceEJB extends Authenticator implements IEmailServiceEJB { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("xxxxxxx@gmail.com", "xxxxxxx"); } public void sendAccountActivationLinkToBuyer(String destinationEmail, String name) { // OUR EMAIL SETTINGS String host = "smtp.gmail.com";// Gmail int port = 465; String serviceUsername = "xxxxxxx@gmail.com"; String servicePassword = "xxxxxxx";// Our Gmail password Properties props = new Properties(); props.put("mail.smtp.user", serviceUsername); props.put("mail.smtp.host", host); props.put("mail.smtp.port", port); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.debug", "true"); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.socketFactory.port", port); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.fallback", "false"); // Destination of the email String to = destinationEmail; String from = "xxxxxxx@gmail.com"; // Creating a javax.Session with the our properties Session session = Session.getInstance(props); try { Message message = new MimeMessage(session); // From: is our service message.setFrom(new InternetAddress(from)); // To: destination given message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); message.setSubject("Comfirm your account"); // Instead of simple text, a .html template should be added here! message.setText("Welcome....... "); Transport transport = session.getTransport("smtp"); transport.connect(host, port, serviceUsername, servicePassword); Transport.send(message, message.getAllRecipients()); transport.close(); } catch (MessagingException e) { throw new RuntimeException(e); } } </code></pre> <p>}</p> <p>I dont know why it keeps saying that the password is not specified? Does the SSLSocketFactory have something to do with it? Do i need to call the getPasswordAuthenticion() method somewhere, or calling the second method from my managed bean is all i need? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload