Change default mail api to apache one
This commit is contained in:
parent
604f2f3ee9
commit
10606a22e6
50
pom.xml
50
pom.xml
@ -51,13 +51,12 @@
|
|||||||
|
|
||||||
<!-- Change Compiler Version (JDK) HERE! -->
|
<!-- Change Compiler Version (JDK) HERE! -->
|
||||||
<javaVersion>1.7</javaVersion>
|
<javaVersion>1.7</javaVersion>
|
||||||
|
|
||||||
<!-- Change Bukkit Version HERE! -->
|
<!-- Change Bukkit Version HERE! -->
|
||||||
<bukkitVersion>1.8.8-R0.1-SNAPSHOT</bukkitVersion>
|
<bukkitVersion>1.8.8-R0.1-SNAPSHOT</bukkitVersion>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>AuthMe-${project.version}</finalName>
|
<finalName>${project.name}</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<targetPath>.</targetPath>
|
<targetPath>.</targetPath>
|
||||||
@ -93,12 +92,6 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<minimizeJar>false</minimizeJar>
|
<minimizeJar>false</minimizeJar>
|
||||||
<!-- TODO: simplify these relocations if possible -->
|
|
||||||
<artifactSet>
|
|
||||||
<excludes>
|
|
||||||
<exclude>com.sun:*</exclude>
|
|
||||||
</excludes>
|
|
||||||
</artifactSet>
|
|
||||||
<relocations>
|
<relocations>
|
||||||
<relocation>
|
<relocation>
|
||||||
<pattern>org.mcstats</pattern>
|
<pattern>org.mcstats</pattern>
|
||||||
@ -108,38 +101,6 @@
|
|||||||
<pattern>com.google.gson</pattern>
|
<pattern>com.google.gson</pattern>
|
||||||
<shadedPattern>fr.xephi.authme.libs.gson</shadedPattern>
|
<shadedPattern>fr.xephi.authme.libs.gson</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
<relocation>
|
|
||||||
<pattern>com.zaxxer.hikari</pattern>
|
|
||||||
<shadedPattern>fr.xephi.authme.libs.hikari</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>org.slf4j</pattern>
|
|
||||||
<shadedPattern>fr.xephi.authme.libs.slf4j</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>javax.mail</pattern>
|
|
||||||
<shadedPattern>fr.xephi.authme.libs.mail</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>javax.activation</pattern>
|
|
||||||
<shadedPattern>fr.xephi.authme.libs.mail.activation</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.sun.mail</pattern>
|
|
||||||
<shadedPattern>fr.xephi.authme.libs.mail</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.sun.activation</pattern>
|
|
||||||
<shadedPattern>fr.xephi.authme.libs.mail.activation</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.maxmind.geoip</pattern>
|
|
||||||
<shadedPattern>fr.xephi.authme.libs.geoip</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>net.ricecode.similarity</pattern>
|
|
||||||
<shadedPattern>fr.xephi.authme.libs.similarity</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
@ -240,19 +201,18 @@
|
|||||||
<!-- Java Email Implementation -->
|
<!-- Java Email Implementation -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.mail</groupId>
|
<groupId>com.sun.mail</groupId>
|
||||||
<artifactId>mailapi</artifactId>
|
<artifactId>javax.mail</artifactId>
|
||||||
<version>1.5.4</version>
|
<version>1.5.4</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.sun.mail</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>smtp</artifactId>
|
<artifactId>commons-email</artifactId>
|
||||||
<version>1.5.4</version>
|
<version>1.4</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- GSON (required to provide 1.7.10 and below compatibility) -->
|
<!-- GSON (required to provide 1.7.10 and below compatibility) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.code.gson</groupId>
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
|||||||
@ -72,7 +72,9 @@ public class AuthMe extends JavaPlugin {
|
|||||||
/** Defines the current AuthMeReloaded version name. */
|
/** Defines the current AuthMeReloaded version name. */
|
||||||
private static final String PLUGIN_VERSION_NAME = "5.1-SNAPSHOT";
|
private static final String PLUGIN_VERSION_NAME = "5.1-SNAPSHOT";
|
||||||
/** Defines the current AuthMeReloaded version code. */
|
/** Defines the current AuthMeReloaded version code. */
|
||||||
private static final int PLUGIN_VERSION_CODE = 100; // Increase this number by one when an update is released
|
private static final int PLUGIN_VERSION_CODE = 100; // Increase this number
|
||||||
|
// by one when an update
|
||||||
|
// is released
|
||||||
|
|
||||||
private static AuthMe plugin;
|
private static AuthMe plugin;
|
||||||
private static Server server;
|
private static Server server;
|
||||||
@ -114,14 +116,14 @@ public class AuthMe extends JavaPlugin {
|
|||||||
private boolean canConnect = true;
|
private boolean canConnect = true;
|
||||||
|
|
||||||
public boolean canConnect() {
|
public boolean canConnect() {
|
||||||
return canConnect;
|
return canConnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCanConnect(boolean canConnect) {
|
public void setCanConnect(boolean canConnect) {
|
||||||
this.canConnect = canConnect;
|
this.canConnect = canConnect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AuthMe getInstance() {
|
public static AuthMe getInstance() {
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -186,18 +188,20 @@ public class AuthMe extends JavaPlugin {
|
|||||||
Graph databaseBackend = metrics.createGraph("Database backend");
|
Graph databaseBackend = metrics.createGraph("Database backend");
|
||||||
|
|
||||||
// Custom graphs
|
// Custom graphs
|
||||||
if(Settings.messageFile.exists()) {
|
if (Settings.messageFile.exists()) {
|
||||||
messagesLanguage.addPlotter(new Metrics.Plotter(Settings.messagesLanguage) {
|
messagesLanguage.addPlotter(new Metrics.Plotter(Settings.messagesLanguage) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
databaseBackend.addPlotter(new Metrics.Plotter(Settings.getDataSource.toString()) {
|
databaseBackend.addPlotter(new Metrics.Plotter(Settings.getDataSource.toString()) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getValue() {
|
public int getValue() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -335,17 +339,19 @@ public class AuthMe extends JavaPlugin {
|
|||||||
pm.registerEvents(new AuthMeEntityListener(this), this);
|
pm.registerEvents(new AuthMeEntityListener(this), this);
|
||||||
pm.registerEvents(new AuthMeServerListener(this), this);
|
pm.registerEvents(new AuthMeServerListener(this), this);
|
||||||
|
|
||||||
// TODO: This is moved to CommandManager.registerCommands() handled by AuthMe.onCommand() -- timvisee
|
// TODO: This is moved to CommandManager.registerCommands() handled by
|
||||||
|
// AuthMe.onCommand() -- timvisee
|
||||||
// Register commands
|
// Register commands
|
||||||
//getCommand("authme").setExecutor(new AdminCommand(this));
|
// getCommand("authme").setExecutor(new AdminCommand(this));
|
||||||
//getCommand("register").setExecutor(new RegisterCommand(this));
|
// getCommand("register").setExecutor(new RegisterCommand(this));
|
||||||
//getCommand("login").setExecutor(new LoginCommand(this));
|
// getCommand("login").setExecutor(new LoginCommand(this));
|
||||||
//getCommand("changepassword").setExecutor(new ChangePasswordCommand(this));
|
// getCommand("changepassword").setExecutor(new
|
||||||
//getCommand("logout").setExecutor(new LogoutCommand(this));
|
// ChangePasswordCommand(this));
|
||||||
//getCommand("unregister").setExecutor(new UnregisterCommand(this));
|
// getCommand("logout").setExecutor(new LogoutCommand(this));
|
||||||
//getCommand("email").setExecutor(new EmailCommand(this));
|
// getCommand("unregister").setExecutor(new UnregisterCommand(this));
|
||||||
//getCommand("captcha").setExecutor(new CaptchaCommand(this));
|
// getCommand("email").setExecutor(new EmailCommand(this));
|
||||||
//getCommand("converter").setExecutor(new ConverterCommand(this));
|
// getCommand("captcha").setExecutor(new CaptchaCommand(this));
|
||||||
|
// getCommand("converter").setExecutor(new ConverterCommand(this));
|
||||||
|
|
||||||
// Purge on start if enabled
|
// Purge on start if enabled
|
||||||
autoPurge();
|
autoPurge();
|
||||||
@ -419,7 +425,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
// Initialize and setup the database
|
// Initialize and setup the database
|
||||||
public void setupDatabase() throws Exception {
|
public void setupDatabase() throws Exception {
|
||||||
if (database != null) database.close();
|
if (database != null)
|
||||||
|
database.close();
|
||||||
// Backend MYSQL - FILE - SQLITE - SQLITEHIKARI
|
// Backend MYSQL - FILE - SQLITE - SQLITEHIKARI
|
||||||
boolean isSQLite = false;
|
boolean isSQLite = false;
|
||||||
switch (Settings.getDataSource) {
|
switch (Settings.getDataSource) {
|
||||||
@ -830,18 +837,23 @@ public class AuthMe extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Handle Bukkit commands.
|
* Handle Bukkit commands.
|
||||||
*
|
*
|
||||||
* @param sender The command sender (Bukkit).
|
* @param sender
|
||||||
* @param cmd The command (Bukkit).
|
* The command sender (Bukkit).
|
||||||
* @param commandLabel The command label (Bukkit).
|
* @param cmd
|
||||||
* @param args The command arguments (Bukkit).
|
* The command (Bukkit).
|
||||||
|
* @param commandLabel
|
||||||
|
* The command label (Bukkit).
|
||||||
|
* @param args
|
||||||
|
* The command arguments (Bukkit).
|
||||||
*
|
*
|
||||||
* @return True if the command was executed, false otherwise.
|
* @return True if the command was executed, false otherwise.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
public boolean onCommand(CommandSender sender, Command cmd,
|
||||||
|
String commandLabel, String[] args) {
|
||||||
// Get the command handler, and make sure it's valid
|
// Get the command handler, and make sure it's valid
|
||||||
CommandHandler commandHandler = this.getCommandHandler();
|
CommandHandler commandHandler = this.getCommandHandler();
|
||||||
if(commandHandler == null)
|
if (commandHandler == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Handle the command, return the result
|
// Handle the command, return the result
|
||||||
@ -851,7 +863,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Get the current installed AuthMeReloaded version name.
|
* Get the current installed AuthMeReloaded version name.
|
||||||
*
|
*
|
||||||
* @return The version name of the currently installed AuthMeReloaded instance.
|
* @return The version name of the currently installed AuthMeReloaded
|
||||||
|
* instance.
|
||||||
*/
|
*/
|
||||||
public static String getVersionName() {
|
public static String getVersionName() {
|
||||||
return PLUGIN_VERSION_NAME;
|
return PLUGIN_VERSION_NAME;
|
||||||
@ -860,7 +873,8 @@ public class AuthMe extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Get the current installed AuthMeReloaded version code.
|
* Get the current installed AuthMeReloaded version code.
|
||||||
*
|
*
|
||||||
* @return The version code of the currently installed AuthMeReloaded instance.
|
* @return The version code of the currently installed AuthMeReloaded
|
||||||
|
* instance.
|
||||||
*/
|
*/
|
||||||
public static int getVersionCode() {
|
public static int getVersionCode() {
|
||||||
return PLUGIN_VERSION_CODE;
|
return PLUGIN_VERSION_CODE;
|
||||||
|
|||||||
@ -1,25 +1,12 @@
|
|||||||
package fr.xephi.authme;
|
package fr.xephi.authme;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.activation.DataHandler;
|
|
||||||
import javax.activation.DataSource;
|
import javax.activation.DataSource;
|
||||||
import javax.activation.FileDataSource;
|
import javax.activation.FileDataSource;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.mail.BodyPart;
|
|
||||||
import javax.mail.Message;
|
|
||||||
import javax.mail.Multipart;
|
|
||||||
import javax.mail.PasswordAuthentication;
|
|
||||||
import javax.mail.Session;
|
|
||||||
import javax.mail.Transport;
|
|
||||||
import javax.mail.internet.InternetAddress;
|
|
||||||
import javax.mail.internet.MimeBodyPart;
|
|
||||||
import javax.mail.internet.MimeMessage;
|
|
||||||
import javax.mail.internet.MimeMultipart;
|
|
||||||
|
|
||||||
|
import org.apache.commons.mail.HtmlEmail;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
@ -47,7 +34,7 @@ public class SendMailSSL {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final String sender = sendername;
|
final String sender = sendername;
|
||||||
final String port = String.valueOf(Settings.getMailPort);
|
final int port = Settings.getMailPort;
|
||||||
final String acc = Settings.getmailAccount;
|
final String acc = Settings.getmailAccount;
|
||||||
final String subject = Settings.getMailSubject;
|
final String subject = Settings.getMailSubject;
|
||||||
final String smtp = Settings.getmailSMTP;
|
final String smtp = Settings.getmailSMTP;
|
||||||
@ -59,35 +46,18 @@ public class SendMailSSL {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
Properties props = new Properties();
|
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
|
||||||
props.put("mail.smtp.host", smtp);
|
HtmlEmail email = new HtmlEmail();
|
||||||
props.put("mail.smtp.auth", "true");
|
email.setSmtpPort(port);
|
||||||
props.put("mail.smtp.port", port);
|
email.setHostName(smtp);
|
||||||
props.put("mail.smtp.socketFactory.port", port);
|
email.addTo(mail);
|
||||||
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
|
email.setFrom(acc, sender);
|
||||||
props.put("mail.smtp.starttls.enable", true);
|
email.setSubject(subject);
|
||||||
props.put("mail.smtp.socketFactory.fallback", false);
|
email.setHtmlMsg(mailText);
|
||||||
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
|
email.setAuthentication(acc, password);
|
||||||
|
email.setStartTLSEnabled(true);
|
||||||
protected PasswordAuthentication getPasswordAuthentication() {
|
email.setStartTLSRequired(true);
|
||||||
return new PasswordAuthentication(acc, password);
|
email.setSSLCheckServerIdentity(true);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Message message = new MimeMessage(session);
|
|
||||||
try {
|
|
||||||
message.setFrom(new InternetAddress(acc, sender));
|
|
||||||
} catch (UnsupportedEncodingException uee) {
|
|
||||||
message.setFrom(new InternetAddress(acc));
|
|
||||||
}
|
|
||||||
message.addRecipient(Message.RecipientType.TO, new InternetAddress(mail));
|
|
||||||
message.setSubject(subject);
|
|
||||||
message.setSentDate(new Date());
|
|
||||||
BodyPart messageBodyPart = new MimeBodyPart();
|
|
||||||
messageBodyPart.setContent(mailText, "text/html");
|
|
||||||
Multipart multipart = new MimeMultipart();
|
|
||||||
multipart.addBodyPart(messageBodyPart);
|
|
||||||
|
|
||||||
// Generate an image ?
|
// Generate an image ?
|
||||||
File file = null;
|
File file = null;
|
||||||
if (Settings.generateImage) {
|
if (Settings.generateImage) {
|
||||||
@ -95,25 +65,17 @@ public class SendMailSSL {
|
|||||||
ImageGenerator gen = new ImageGenerator(newPass);
|
ImageGenerator gen = new ImageGenerator(newPass);
|
||||||
file = new File(plugin.getDataFolder() + File.separator + auth.getNickname() + "_new_pass.jpg");
|
file = new File(plugin.getDataFolder() + File.separator + auth.getNickname() + "_new_pass.jpg");
|
||||||
ImageIO.write(gen.generateImage(), "jpg", file);
|
ImageIO.write(gen.generateImage(), "jpg", file);
|
||||||
messageBodyPart = new MimeBodyPart();
|
|
||||||
DataSource source = new FileDataSource(file);
|
DataSource source = new FileDataSource(file);
|
||||||
messageBodyPart.setDataHandler(new DataHandler(source));
|
email.embed(source, auth.getNickname() + "_new_pass.jpg");
|
||||||
messageBodyPart.setFileName(auth.getNickname() + "_new_pass.jpg");
|
|
||||||
multipart.addBodyPart(messageBodyPart);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ConsoleLogger.showError("Unable to send new password as image! Using normal text! Dest: " + mail);
|
ConsoleLogger.showError("Unable to send new password as image! Using normal text! Dest: " + mail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
message.setContent(multipart);
|
|
||||||
try {
|
try {
|
||||||
Transport transport = session.getTransport("smtp");
|
email.send();
|
||||||
transport.connect(smtp, Integer.parseInt(port), acc, password);
|
|
||||||
transport.sendMessage(message, message.getAllRecipients());
|
|
||||||
transport.close();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
ConsoleLogger.showError("Cannot send email to " + mail + ", an error occured!");
|
ConsoleLogger.showError("Fail to send a mail to " + mail);
|
||||||
}
|
}
|
||||||
if (file != null)
|
if (file != null)
|
||||||
file.delete();
|
file.delete();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user