• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail Authentication Problem  RSS feed

 
Tobias Keiler
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

we try to write a communication application and implemented a Standard Authentication Class into our EmailManager Class. There's a method which calls a new Authentication Object and tries to send the mail.

Now the problem:

If we leave the button "SMTP Authentication" unchecked, an exception comes up which tells us that there's an authentication required (550 5.7.0 Need to authenticate via SMTP-AUTH-Login {mp026})

The other way, if we check it (this turns the auth true--> properties.put("mail.smtp.auth","true")), then there comes up the following:

javax.mail.AuthenticationFailedException: failed to connect
at javax.mail.Service.connect(Service.java:322)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at controller.EmailManager.sendMail(EmailManager.java:92)
at gui.CreateEmail.actionPerformed(CreateEmail.java:111)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Can somebody please help us? We tried to google anything and don't see any mistakes we could have made.

Here's the code of the sendMail method:

public void sendMail(Email email, Konto konto){
MailAuthenticator auth = new MailAuthenticator(konto.getUsername(), konto.getPassword());

Properties properties = new Properties();

// System.out.println(konto.getUsername());
// System.out.println(konto.getPassword());
// System.out.println(konto.getSmtpHost());
// System.out.println(konto.getPopHost());
// System.out.println(konto.getSenderAddress());
// System.out.println(email.getSenderAddress());
// System.out.println(email.getRecieverAddress());
// System.out.println(email.getText());
// System.out.println(email.getSubject());
// Den Properties wird die ServerAdresse hinzugefügt
properties.put("mail.smtp.host", konto.getSmtpHost());
properties.put("mail.smtp.user", konto.getUsername());
properties.put("mail.smtp.password", konto.getPassword());

// !!Wichtig!! Falls der SMTP-Server eine Authentifizierung
// verlangt
// muss an dieser Stelle die Property auf "true" gesetzt
// werden
System.out.println(""+Boolean.toString(konto.isAuth()));

properties.put("mail.smtp.auth","true");
//properties.setProperty( "mail.smtp.port", "587");

// Hier wird mit den Properties und dem implements Contructor
// erzeugten
// MailAuthenticator eine Session erzeugt
Session session = Session.getDefaultInstance(properties, auth);

try {
// Eine neue Message erzeugen
Message msg = new MimeMessage(session);

// Hier werden die Absender- und Empfängeradressen gesetzt
msg.setFrom(new InternetAddress(email.getSenderAddress()));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
email.getRecieverAddress(), false));

// Der Betreff und Body der Message werden gesetzt
msg.setSubject(email.getSubject());
msg.setText(email.getText());

// Hier lassen sich HEADER-Informationen hinzufügen
msg.setHeader("Test", "Test");

Date sendDate = OurCalendar.getNowDate();
msg.setSentDate(sendDate);
email.setSendDate(sendDate);

// Zum Schluss wird die Mail natürlich noch verschickt
Transport.send(msg);

}
catch (Exception e) {
e.printStackTrace( );
}
}

Many Thanks in advance

Collinwood

 
Rob Spoor
Sheriff
Posts: 20895
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please Use Code Tags.

Tobias Keiler wrote:properties.put("mail.smtp.password", konto.getPassword());

Try using "mail.smtp.pass" instead.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!