Skip to content

The Unified and Autonomous Development Platform

fix issue #67: Error when sending test mail

Robin Shen4c2cf7af1362
diff --git a/server-core/src/main/java/io/onedev/server/migration/DataMigrator.java b/server-core/src/main/java/io/onedev/server/migration/DataMigrator.java
index e0465e83bc..e4f1dbb1fe 100644
--- a/server-core/src/main/java/io/onedev/server/migration/DataMigrator.java
+++ b/server-core/src/main/java/io/onedev/server/migration/DataMigrator.java
@@ -1592,6 +1592,7 @@ public class DataMigrator {
return projectId;
}
+ // from 3.0.10 to 3.0.11
private void migrate38(File dataDir, Stack<Integer> versions) {
Map<Long, Long> forkedFroms = new HashMap<>();
@@ -1674,13 +1675,15 @@ public class DataMigrator {
} else if (file.getName().startsWith("Settings.xml")) {
VersionedDocument dom = VersionedDocument.fromFile(file);
for (Element element: dom.getRootElement().elements()) {
- Long projectId = Long.valueOf(element.elementTextTrim("id"));
- Element forkedFromElement = element.element("forkedFrom");
- if (forkedFromElement != null)
- forkedFroms.put(projectId, Long.valueOf(forkedFromElement.getTextTrim()));
- else
- forkedFroms.put(projectId, null);
- }
+ if (element.elementTextTrim("key").equals("MAIL")) {
+ Element valueElement = element.element("value");
+ if (valueElement != null) {
+ valueElement.addElement("enableStartTLS").setText("true");
+ valueElement.element("enableSSL").detach();
+ }
+ }
+ }
+ dom.writeToFile(file, false);
}
}
diff --git a/server-core/src/main/java/io/onedev/server/model/support/administration/MailSetting.java b/server-core/src/main/java/io/onedev/server/model/support/administration/MailSetting.java
index e615ab3cb9..56319a2c3f 100644
--- a/server-core/src/main/java/io/onedev/server/model/support/administration/MailSetting.java
+++ b/server-core/src/main/java/io/onedev/server/model/support/administration/MailSetting.java
@@ -1,109 +1,106 @@
-package io.onedev.server.model.support.administration;
-
-import java.io.Serializable;
-
-import org.hibernate.validator.constraints.NotEmpty;
-
-import io.onedev.server.web.editable.annotation.Editable;
-import io.onedev.server.web.editable.annotation.Password;
-
-@Editable
-public class MailSetting implements Serializable {
-
- private static final long serialVersionUID = 1L;
-
- private String smtpHost;
-
- private int smtpPort = 587;
-
- private boolean enableSSL;
-
- private String smtpUser;
-
- private String smtpPassword;
-
- private String senderAddress;
-
- private int timeout = 60;
-
- @Editable(order=100, name="SMTP Host", description=
- "Specify the SMTP mail host used by OneDev to send email."
- )
- @NotEmpty
- public String getSmtpHost() {
- return smtpHost;
- }
-
- public void setSmtpHost(String smtpHost) {
- this.smtpHost = smtpHost;
- }
-
- @Editable(order=200, name="SMTP Port", description=
- "Specify port number for the above SMTP host. This port number "
- + "will be used if the option 'Use SMTP over SSL' is not checked."
- )
- public int getSmtpPort() {
- return smtpPort;
- }
-
- public void setSmtpPort(int smtpPort) {
- this.smtpPort = smtpPort;
- }
-
- @Editable(order=250, name="Enable SSL", description="Whether or not to enable SSL")
- public boolean isEnableSSL() {
- return enableSSL;
- }
-
- public void setEnableSSL(boolean enableSSL) {
- this.enableSSL = enableSSL;
- }
-
- @Editable(order=300, name="SMTP User", description=
- "Optionally specify user name here if the SMTP host needs authentication"
- )
- public String getSmtpUser() {
- return smtpUser;
- }
-
- public void setSmtpUser(String smtpUser) {
- this.smtpUser = smtpUser;
- }
-
- @Editable(order=400, name="SMTP Password", description=
- "Optionally specify password here if the SMTP host needs authentication"
- )
- @Password(autoComplete="new-password")
- public String getSmtpPassword() {
- return smtpPassword;
- }
-
- public void setSmtpPassword(String smtpPassword) {
- this.smtpPassword = smtpPassword;
- }
-
- @Editable(order=500, description=
- "This property is optional. If specified, OneDev will use this email " +
- "as the sender address when sending out emails. Otherwise, the sender " +
- "address will be <b>onedev@&lt;hostname&gt;</b>, where &lt;hostname&gt; " +
- "is the host name of OneDev server."
- )
- public String getSenderAddress() {
- return senderAddress;
- }
-
- public void setSenderAddress(String senderAddress) {
- this.senderAddress = senderAddress;
- }
-
- @Editable(order=600, description="Specify timeout in seconds when communicating with the SMTP server. " +
- "Use 0 to set an infinite timeout.")
- public int getTimeout() {
- return timeout;
- }
-
- public void setTimeout(int timeout) {
- this.timeout = timeout;
- }
-
-}
+package io.onedev.server.model.support.administration;
+
+import java.io.Serializable;
+
+import org.hibernate.validator.constraints.NotEmpty;
+
+import io.onedev.server.web.editable.annotation.Editable;
+import io.onedev.server.web.editable.annotation.Password;
+
+@Editable
+public class MailSetting implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private String smtpHost;
+
+ private int smtpPort = 587;
+
+ private boolean enableStartTLS;
+
+ private String smtpUser;
+
+ private String smtpPassword;
+
+ private String senderAddress;
+
+ private int timeout = 60;
+
+ @Editable(order=100, name="SMTP Host", description=
+ "Specify the SMTP mail host used by OneDev to send email."
+ )
+ @NotEmpty
+ public String getSmtpHost() {
+ return smtpHost;
+ }
+
+ public void setSmtpHost(String smtpHost) {
+ this.smtpHost = smtpHost;
+ }
+
+ @Editable(order=200, name="SMTP Port")
+ public int getSmtpPort() {
+ return smtpPort;
+ }
+
+ public void setSmtpPort(int smtpPort) {
+ this.smtpPort = smtpPort;
+ }
+
+ @Editable(order=250, name="Enable STARTTLS", description="Whether or not to enable STARTTLS on above port")
+ public boolean isEnableStartTLS() {
+ return enableStartTLS;
+ }
+
+ public void setEnableStartTLS(boolean enableStartTLS) {
+ this.enableStartTLS = enableStartTLS;
+ }
+
+ @Editable(order=300, name="SMTP User", description=
+ "Optionally specify user name here if the SMTP host needs authentication"
+ )
+ public String getSmtpUser() {
+ return smtpUser;
+ }
+
+ public void setSmtpUser(String smtpUser) {
+ this.smtpUser = smtpUser;
+ }
+
+ @Editable(order=400, name="SMTP Password", description=
+ "Optionally specify password here if the SMTP host needs authentication"
+ )
+ @Password(autoComplete="new-password")
+ public String getSmtpPassword() {
+ return smtpPassword;
+ }
+
+ public void setSmtpPassword(String smtpPassword) {
+ this.smtpPassword = smtpPassword;
+ }
+
+ @Editable(order=500, description=
+ "This property is optional. If specified, OneDev will use this email " +
+ "as the sender address when sending out emails. Otherwise, the sender " +
+ "address will be <b>onedev@&lt;hostname&gt;</b>, where &lt;hostname&gt; " +
+ "is the host name of OneDev server."
+ )
+ public String getSenderAddress() {
+ return senderAddress;
+ }
+
+ public void setSenderAddress(String senderAddress) {
+ this.senderAddress = senderAddress;
+ }
+
+ @Editable(order=600, description="Specify timeout in seconds when communicating with the SMTP server. " +
+ "Use 0 to set an infinite timeout.")
+ public int getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(int timeout) {
+ this.timeout = timeout;
+ }
+
+}
diff --git a/server-core/src/main/java/io/onedev/server/notification/DefaultMailManager.java b/server-core/src/main/java/io/onedev/server/notification/DefaultMailManager.java
index c56072246a..bd452657d0 100644
--- a/server-core/src/main/java/io/onedev/server/notification/DefaultMailManager.java
+++ b/server-core/src/main/java/io/onedev/server/notification/DefaultMailManager.java
@@ -78,8 +78,8 @@ public class DefaultMailManager implements MailManager {
if (mailSetting.getTimeout() != 0)
email.setSocketTimeout(mailSetting.getTimeout()*1000);
- email.setStartTLSEnabled(true);
- email.setSSLOnConnect(mailSetting.isEnableSSL());
+ email.setStartTLSEnabled(mailSetting.isEnableStartTLS());
+ email.setSSLOnConnect(false);
email.setSSLCheckServerIdentity(false);
String senderEmail = mailSetting.getSenderAddress();