mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-03 01:00:18 +01:00
#1075 Mail sender - allow to turn off TLS for port 25
This commit is contained in:
parent
a2b8ca683d
commit
a847deac16
@ -30,6 +30,7 @@ import fr.xephi.authme.service.BackupService;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.MigrationService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
@ -269,6 +270,12 @@ public class AuthMe extends JavaPlugin {
|
||||
&& settings.getProperty(PluginSettings.SESSIONS_ENABLED)) {
|
||||
ConsoleLogger.warning("WARNING!!! You set session timeout to 0, this may cause security issues!");
|
||||
}
|
||||
|
||||
// Use TLS property only affects port 25
|
||||
if (!settings.getProperty(EmailSettings.PORT25_USE_TLS)
|
||||
&& settings.getProperty(EmailSettings.SMTP_PORT) != 25) {
|
||||
ConsoleLogger.warning("Note: You have set Email.useTls to false but this only affects mail over port 25");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,13 @@
|
||||
package fr.xephi.authme.command.executable.authme.debug;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.mail.EmailService;
|
||||
import fr.xephi.authme.mail.SendMailSSL;
|
||||
import org.apache.commons.mail.EmailException;
|
||||
import org.apache.commons.mail.HtmlEmail;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -18,7 +22,10 @@ class TestEmailSender implements DebugSection {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private EmailService emailService;
|
||||
private SendMailSSL sendMailSSL;
|
||||
|
||||
@Inject
|
||||
private Server server;
|
||||
|
||||
|
||||
@Override
|
||||
@ -33,7 +40,7 @@ class TestEmailSender implements DebugSection {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, List<String> arguments) {
|
||||
if (!emailService.hasAllInformation()) {
|
||||
if (!sendMailSSL.hasAllInformation()) {
|
||||
sender.sendMessage(ChatColor.RED + "You haven't set all required configurations in config.yml " +
|
||||
"for sending emails. Please check your config.yml");
|
||||
return;
|
||||
@ -43,7 +50,7 @@ class TestEmailSender implements DebugSection {
|
||||
|
||||
// getEmail() takes care of informing the sender of the error if email == null
|
||||
if (email != null) {
|
||||
boolean sendMail = emailService.sendTestEmail(email);
|
||||
boolean sendMail = sendTestEmail(email);
|
||||
if (sendMail) {
|
||||
sender.sendMessage("Test email sent to " + email + " with success");
|
||||
} else {
|
||||
@ -75,4 +82,19 @@ class TestEmailSender implements DebugSection {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean sendTestEmail(String email) {
|
||||
HtmlEmail htmlEmail;
|
||||
try {
|
||||
htmlEmail = sendMailSSL.initializeMail(email);
|
||||
} catch (EmailException e) {
|
||||
ConsoleLogger.logException("Failed to create email for sample email:", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
htmlEmail.setSubject("AuthMe test email");
|
||||
String message = "Hello there!<br />This is a sample email sent to you from a Minecraft server ("
|
||||
+ server.getName() + ") via /authme debug mail. If you're seeing this, sending emails should be fine.";
|
||||
return sendMailSSL.sendEmail(message, htmlEmail);
|
||||
}
|
||||
}
|
||||
|
@ -94,21 +94,6 @@ public class EmailService {
|
||||
return sendMailSSL.sendEmail(message, htmlEmail);
|
||||
}
|
||||
|
||||
public boolean sendTestEmail(String email) {
|
||||
HtmlEmail htmlEmail;
|
||||
try {
|
||||
htmlEmail = sendMailSSL.initializeMail(email);
|
||||
} catch (EmailException e) {
|
||||
ConsoleLogger.logException("Failed to create email for sample email:", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
htmlEmail.setSubject("AuthMe test email");
|
||||
String message = "Hello there!<br />This is a sample email sent to you from a Minecraft server ("
|
||||
+ serverName + ") via /authme debug mail. If you're seeing this, sending emails should be fine.";
|
||||
return sendMailSSL.sendEmail(message, htmlEmail);
|
||||
}
|
||||
|
||||
private File generateImage(String name, String newPass) throws IOException {
|
||||
ImageGenerator gen = new ImageGenerator(newPass);
|
||||
File file = new File(dataFolder, name + "_new_pass.jpg");
|
||||
|
@ -24,12 +24,8 @@ import static fr.xephi.authme.settings.properties.EmailSettings.MAIL_PASSWORD;
|
||||
*/
|
||||
public class SendMailSSL {
|
||||
|
||||
private final Settings settings;
|
||||
|
||||
@Inject
|
||||
SendMailSSL(Settings settings) {
|
||||
this.settings = settings;
|
||||
}
|
||||
private Settings settings;
|
||||
|
||||
/**
|
||||
* Returns whether all necessary settings are set for sending mails.
|
||||
@ -115,8 +111,10 @@ public class SendMailSSL {
|
||||
}
|
||||
break;
|
||||
case 25:
|
||||
email.setStartTLSEnabled(true);
|
||||
email.setSSLCheckServerIdentity(true);
|
||||
if (settings.getProperty(EmailSettings.PORT25_USE_TLS)) {
|
||||
email.setStartTLSEnabled(true);
|
||||
email.setSSLCheckServerIdentity(true);
|
||||
}
|
||||
break;
|
||||
case 465:
|
||||
email.setSslSmtpPort(Integer.toString(port));
|
||||
|
@ -19,6 +19,10 @@ public class EmailSettings implements SettingsHolder {
|
||||
public static final Property<Integer> SMTP_PORT =
|
||||
newProperty("Email.mailPort", 465);
|
||||
|
||||
@Comment("Only affects port 25: enable TLS/STARTTLS?")
|
||||
public static final Property<Boolean> PORT25_USE_TLS =
|
||||
newProperty("Email.useTls", true);
|
||||
|
||||
@Comment("Email account which sends the mails")
|
||||
public static final Property<String> MAIL_ACCOUNT =
|
||||
newProperty("Email.mailAccount", "");
|
||||
|
Loading…
Reference in New Issue
Block a user