Skip to content

Commit d05746b

Browse files
arvindsvvarshavaradarajan
authored andcommitted
Added a friendlier error message on failing to send test email.
1 parent 27511b3 commit d05746b

File tree

6 files changed

+27
-35
lines changed

6 files changed

+27
-35
lines changed

server/src/com/thoughtworks/go/config/BackgroundMailSender.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1-
/*************************GO-LICENSE-START*********************************
2-
* Copyright 2014 ThoughtWorks, Inc.
1+
/*
2+
* Copyright 2016 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*************************GO-LICENSE-END***********************************/
15+
*/
1616

1717
package com.thoughtworks.go.config;
1818

1919
import com.thoughtworks.go.domain.materials.ValidationBean;
2020
import com.thoughtworks.go.server.messaging.SendEmailMessage;
2121
import com.thoughtworks.go.util.GoConstants;
2222
import com.thoughtworks.go.util.SystemEnvironment;
23+
import org.apache.commons.logging.Log;
24+
import org.apache.commons.logging.LogFactory;
2325

2426
public class BackgroundMailSender implements GoMailSender {
27+
private static final Log LOGGER = LogFactory.getLog(BackgroundMailSender.class);
2528

2629
private static final Integer CRUISE_MAIL_SENDER_TIMEOUT = Integer.parseInt(
2730
SystemEnvironment.getProperty("cruise.mail.sender.timeout", String.valueOf(GoConstants.DEFAULT_TIMEOUT)));
2831

2932
private ValidationBean validation;
3033
private GoMailSender mailSender;
3134
private int timeout;
32-
private static final String ERROR_MESSAGE = "Timeout when sending email."
33-
+ " Make sure your host, port, username, password and tls configuration are correct";
3435

3536
public BackgroundMailSender(GoMailSender sender) {
3637
this(sender, CRUISE_MAIL_SENDER_TIMEOUT);
@@ -60,13 +61,12 @@ private ValidationBean execute(Runnable action) {
6061
thread.join(timeout);
6162
if (thread.isAlive()) {
6263
thread.interrupt();
63-
return ValidationBean.notValid(
64-
ERROR_MESSAGE);
64+
return ValidationBean.notValid(ERROR_MESSAGE);
6565
}
6666
return validation;
6767
} catch (InterruptedException e) {
68-
return ValidationBean.notValid(
69-
ERROR_MESSAGE);
68+
LOGGER.error("Timed out when sending an email. Please check email configuration.");
69+
return ValidationBean.notValid(ERROR_MESSAGE);
7070
}
7171
}
7272

server/src/com/thoughtworks/go/config/GoMailSender.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
/*************************GO-LICENSE-START*********************************
2-
* Copyright 2014 ThoughtWorks, Inc.
1+
/*
2+
* Copyright 2016 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*************************GO-LICENSE-END***********************************/
15+
*/
1616

1717
package com.thoughtworks.go.config;
1818

1919
import com.thoughtworks.go.domain.materials.ValidationBean;
2020
import com.thoughtworks.go.server.messaging.SendEmailMessage;
2121

2222
public interface GoMailSender {
23+
String ERROR_MESSAGE = "Failed to send an email. Please check the GoCD server logs for any extra information that might be present.";
2324

2425
ValidationBean send(String subject, String body, String to);
2526

server/src/com/thoughtworks/go/config/GoSmtpMailSender.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
/*************************GO-LICENSE-START*********************************
2-
* Copyright 2014 ThoughtWorks, Inc.
1+
/*
2+
* Copyright 2016 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*************************GO-LICENSE-END***********************************/
15+
*/
1616

1717
package com.thoughtworks.go.config;
1818

@@ -90,18 +90,9 @@ public ValidationBean send(String subject, String body, String to) {
9090
MimeMessage msg = session.createMessage(from, to, subject, body);
9191
transport.sendMessage(msg, msg.getRecipients(TO));
9292
return ValidationBean.valid();
93-
} catch (AuthenticationFailedException e) {
94-
LOGGER.error(String.format("Sending failed for email [%s] to [%s]", subject, to), e);
95-
return ValidationBean.notValid("Failed to send the email. Caused by: Authentication failed");
96-
} catch (NoSuchProviderException e) {
97-
LOGGER.error(String.format("Sending failed for email [%s] to [%s]", subject, to), e);
98-
return ValidationBean.notValid("Failed to send the email. Caused by: " + e.getMessage());
99-
} catch (MessagingException e) {
100-
LOGGER.error(String.format("Sending failed for email [%s] to [%s]", subject, to), e);
101-
return ValidationBean.notValid("Failed to send the email. Caused by: " + e.getMessage());
10293
} catch (Exception e) {
10394
LOGGER.error(String.format("Sending failed for email [%s] to [%s]", subject, to), e);
104-
return ValidationBean.notValid("Failed to send the email. Caused by: " + e.getMessage());
95+
return ValidationBean.notValid(ERROR_MESSAGE);
10596
} finally {
10697
if (transport != null) {
10798
try {

server/test/unit/com/thoughtworks/go/config/BackgroundEmailSenderTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
/*************************GO-LICENSE-START*********************************
2-
* Copyright 2014 ThoughtWorks, Inc.
1+
/*
2+
* Copyright 2016 ThoughtWorks, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
15-
*************************GO-LICENSE-END***********************************/
15+
*/
1616

1717
package com.thoughtworks.go.config;
1818

@@ -61,7 +61,7 @@ public void shouldReturnNotValidIfSendingTimesout() {
6161
BackgroundMailSender background = new BackgroundMailSender(neverReturns, 1);
6262
ValidationBean validationBean = background.send("Subject", "body", "to@someone");
6363
assertThat(validationBean.isValid(), is(false));
64-
assertThat(validationBean.getError(), containsString("Timeout when sending email"));
64+
assertThat(validationBean.getError(), containsString("Failed to send an email. Please check the GoCD server logs for any extra information that might be present."));
6565
}
6666

6767
@Test

server/webapp/localize.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
<entry key="INVALID_ADMIN_ADDRESS">Admin address is not a valid email address.</entry>
242242
<entry key="INVALID_EMAIL">Not a valid email address.</entry>
243243
<entry key="VALID_VALUE">Valid</entry>
244-
<entry key="FAILED_TO_SEND_TEST_MAIL">Failed to send test mail because: {0}</entry>
244+
<entry key="FAILED_TO_SEND_TEST_MAIL">Email: {0}</entry>
245245
<entry key="SENT_TEST_MAIL_SUCCESSFULLY">Sent test email successfully.</entry>
246246
<entry key="INVALID_TLS">TLS should be selected.</entry>
247247
<entry key="ADMIN_ADDRESS_REQUIRED">Admin email address is required.</entry>

server/webapp/localize_ja.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
<entry key="INVALID_ADMIN_ADDRESS">Admin address is not a valid email address.</entry>
240240
<entry key="INVALID_EMAIL">Not a valid email address.</entry>
241241
<entry key="VALID_VALUE">Valid</entry>
242-
<entry key="FAILED_TO_SEND_TEST_MAIL">Failed to send test mail because: {0}</entry>
242+
<entry key="FAILED_TO_SEND_TEST_MAIL">Email: {0}</entry>
243243
<entry key="SENT_TEST_MAIL_SUCCESSFULLY">Sent test email successfully.</entry>
244244
<entry key="INVALID_TLS">TLS should be selected.</entry>
245245
<entry key="ADMIN_ADDRESS_REQUIRED">Admin email address is required.</entry>

0 commit comments

Comments
 (0)