KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm writing a small Java app using JavaMail that sends the user an automated email. They can choose between (for now) two ports: 25 and 587. The port can be selected via a radio button on the GUI. I added a test button to allow the user to test the email settings (including port). However, for some reason, once the user tries to send a test email, the port can't be changed. Javamail will always use the port of the original test email. Example: User tries to send an email on port 25 and JavaMail says it can not connect on port 25 (for example, the SMTP host uses another port). User clicks port 587, and tries to send a new email. JavaMail throws an error saying it can not connect on port 25, again. I'm kind of stumped as to why. Every time a new test email is sent an entirely new SendMailUsingAuthentication object is created. Within that class the properties are always reset to the proper port. Whenever I debug, as far as I can see, all variables are correct and associated with the correct port. Is there something going on inside of Transport that I'm missing? In the front end GUI: private void testButtonActionPerformed(java.awt.event.ActionEvent evt) { int port = port25RadioButton.isSelected() ? PORT_25 : PORT_587; notifier = new SendMailUsingAuthentication(hostNameTextField.getText(), userTextField.getText(), getPassword(), emailTextField.getText().split(","),port); Thread wait = new Thread(new Runnable() { public void run() { try { changeStatusText("Sending test email..."); notifier.postTestMail(); changeStatusText("Test email sent."); } catch (AddressException ex) { changeStatusText("Error. Invalid email address name."); } catch (MessagingException ex) { changeStatusText("SMTP host connection refused.");
Tags (comma-separated)
Save Edits
Cancel