mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-24 03:05:17 +01:00
Do mail full async
This commit is contained in:
parent
017a55ae13
commit
4ca92dda59
@ -40,28 +40,38 @@ public class SendMailSSL {
|
|||||||
sendername = Settings.getmailSenderName;
|
sendername = Settings.getmailSenderName;
|
||||||
}
|
}
|
||||||
|
|
||||||
String port = String.valueOf(Settings.getMailPort);
|
final String sender = sendername;
|
||||||
|
final String port = String.valueOf(Settings.getMailPort);
|
||||||
|
final String acc = Settings.getmailAccount;
|
||||||
|
final String subject = Settings.getMailSubject;
|
||||||
|
final String smtp = Settings.getmailSMTP;
|
||||||
|
final String password = Settings.getmailPassword;
|
||||||
|
final String mailText = Settings.getMailText;
|
||||||
|
final String mail = auth.getEmail();
|
||||||
|
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
Properties props = new Properties();
|
Properties props = new Properties();
|
||||||
props.put("mail.smtp.host", Settings.getmailSMTP);
|
props.put("mail.smtp.host", smtp);
|
||||||
props.put("mail.smtp.auth", "true");
|
props.put("mail.smtp.auth", "true");
|
||||||
props.put("mail.smtp.port", port);
|
props.put("mail.smtp.port", port);
|
||||||
props.put("mail.smtp.starttls.enable", true);
|
props.put("mail.smtp.starttls.enable", true);
|
||||||
|
|
||||||
try {
|
|
||||||
Session session = Session.getInstance(props, null);
|
Session session = Session.getInstance(props, null);
|
||||||
|
|
||||||
final Message message = new MimeMessage(session);
|
Message message = new MimeMessage(session);
|
||||||
try {
|
try {
|
||||||
message.setFrom(new InternetAddress(Settings.getmailAccount, sendername));
|
message.setFrom(new InternetAddress(acc, sender));
|
||||||
} catch (UnsupportedEncodingException uee) {
|
} catch (UnsupportedEncodingException uee) {
|
||||||
message.setFrom(new InternetAddress(Settings.getmailAccount));
|
message.setFrom(new InternetAddress(acc));
|
||||||
}
|
}
|
||||||
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(auth.getEmail()));
|
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(mail));
|
||||||
message.setSubject(Settings.getMailSubject);
|
message.setSubject(subject);
|
||||||
message.setSentDate(new Date());
|
message.setSentDate(new Date());
|
||||||
BodyPart messageBodyPart = new MimeBodyPart();
|
BodyPart messageBodyPart = new MimeBodyPart();
|
||||||
String text = Settings.getMailText;
|
messageBodyPart.setText(mailText);
|
||||||
messageBodyPart.setText(text);
|
|
||||||
|
|
||||||
Multipart multipart = new MimeMultipart();
|
Multipart multipart = new MimeMultipart();
|
||||||
|
|
||||||
@ -71,22 +81,15 @@ public class SendMailSSL {
|
|||||||
|
|
||||||
multipart.addBodyPart(messageBodyPart);
|
multipart.addBodyPart(messageBodyPart);
|
||||||
message.setContent(multipart);
|
message.setContent(multipart);
|
||||||
final Transport transport = session.getTransport("smtp");
|
Transport transport = session.getTransport("smtp");
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
transport.connect(smtp, acc, password);
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
|
||||||
transport.connect(Settings.getmailSMTP, Settings.getmailAccount, Settings.getmailPassword);
|
|
||||||
transport.sendMessage(message, message.getAllRecipients());
|
transport.sendMessage(message, message.getAllRecipients());
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Some error occured while trying to send a mail to " + auth.getEmail());
|
System.out.println("Some error occured while trying to send a mail to " + mail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("Some error occured while trying to send a mail to " + auth.getEmail());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user