use of org.apache.commons.mail.HtmlEmail in project AuthMeReloaded by AuthMe.
the class EmailService method sendVerificationMail.
/**
* Sends an email to the user with the temporary verification code.
*
* @param name the name of the player
* @param mailAddress the player's email
* @param code the verification code
* @return true if email could be sent, false otherwise
*/
public boolean sendVerificationMail(String name, String mailAddress, String code) {
if (!hasAllInformation()) {
logger.warning("Cannot send verification email: not all email settings are complete");
return false;
}
HtmlEmail email;
try {
email = sendMailSsl.initializeMail(mailAddress);
} catch (EmailException e) {
logger.logException("Failed to create verification email with the given settings:", e);
return false;
}
String mailText = replaceTagsForVerificationEmail(settings.getVerificationEmailMessage(), name, code, settings.getProperty(SecuritySettings.VERIFICATION_CODE_EXPIRATION_MINUTES));
return sendMailSsl.sendEmail(mailText, email);
}
use of org.apache.commons.mail.HtmlEmail in project AuthMeReloaded by AuthMe.
the class EmailService method sendRecoveryCode.
/**
* Sends an email to the user with a recovery code for the password recovery process.
*
* @param name the name of the player
* @param email the player's email address
* @param code the recovery code
* @return true if email could be sent, false otherwise
*/
public boolean sendRecoveryCode(String name, String email, String code) {
HtmlEmail htmlEmail;
try {
htmlEmail = sendMailSsl.initializeMail(email);
} catch (EmailException e) {
logger.logException("Failed to create email for recovery code:", e);
return false;
}
String message = replaceTagsForRecoveryCodeMail(settings.getRecoveryCodeEmailMessage(), name, code, settings.getProperty(SecuritySettings.RECOVERY_CODE_HOURS_VALID));
return sendMailSsl.sendEmail(message, htmlEmail);
}
use of org.apache.commons.mail.HtmlEmail in project AuthMeReloaded by AuthMe.
the class EmailService method sendPasswordMail.
/**
* Sends an email to the user with his new password.
*
* @param name the name of the player
* @param mailAddress the player's email
* @param newPass the new password
* @return true if email could be sent, false otherwise
*/
public boolean sendPasswordMail(String name, String mailAddress, String newPass) {
if (!hasAllInformation()) {
logger.warning("Cannot perform email registration: not all email settings are complete");
return false;
}
HtmlEmail email;
try {
email = sendMailSsl.initializeMail(mailAddress);
} catch (EmailException e) {
logger.logException("Failed to create email with the given settings:", e);
return false;
}
String mailText = replaceTagsForPasswordMail(settings.getPasswordEmailMessage(), name, newPass);
// Generate an image?
File file = null;
if (settings.getProperty(EmailSettings.PASSWORD_AS_IMAGE)) {
try {
file = generatePasswordImage(name, newPass);
mailText = embedImageIntoEmailContent(file, email, mailText);
} catch (IOException | EmailException e) {
logger.logException("Unable to send new password as image for email " + mailAddress + ":", e);
}
}
boolean couldSendEmail = sendMailSsl.sendEmail(mailText, email);
FileUtils.delete(file);
return couldSendEmail;
}
use of org.apache.commons.mail.HtmlEmail in project AuthMeReloaded by AuthMe.
the class SendMailSslTest method shouldCreateEmailObjectWithAddress.
@Test
public void shouldCreateEmailObjectWithAddress() throws EmailException {
// given
given(settings.getProperty(EmailSettings.SMTP_PORT)).willReturn(465);
String smtpHost = "mail.example.com";
given(settings.getProperty(EmailSettings.SMTP_HOST)).willReturn(smtpHost);
String senderAccount = "exampleAccount";
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn(senderAccount);
String senderAddress = "mail@example.com";
given(settings.getProperty(EmailSettings.MAIL_ADDRESS)).willReturn(senderAddress);
String senderName = "Server administration";
given(settings.getProperty(EmailSettings.MAIL_SENDER_NAME)).willReturn(senderName);
// when
HtmlEmail email = sendMailSsl.initializeMail("recipient@example.com");
// then
assertThat(email, not(nullValue()));
assertThat(email.getToAddresses(), hasSize(1));
assertThat(email.getToAddresses().get(0).getAddress(), equalTo("recipient@example.com"));
assertThat(email.getFromAddress().getAddress(), equalTo(senderAddress));
assertThat(email.getFromAddress().getPersonal(), equalTo(senderName));
assertThat(email.getHostName(), equalTo(smtpHost));
assertThat(email.getSmtpPort(), equalTo("465"));
}
use of org.apache.commons.mail.HtmlEmail in project AuthMeReloaded by AuthMe.
the class SendMailSslTest method shouldCreateEmailObject.
@Test
public void shouldCreateEmailObject() throws EmailException {
// given
given(settings.getProperty(EmailSettings.SMTP_PORT)).willReturn(465);
String smtpHost = "mail.example.com";
given(settings.getProperty(EmailSettings.SMTP_HOST)).willReturn(smtpHost);
String senderAccount = "sender@example.org";
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn(senderAccount);
String senderName = "Server administration";
given(settings.getProperty(EmailSettings.MAIL_SENDER_NAME)).willReturn(senderName);
given(settings.getProperty(PluginSettings.LOG_LEVEL)).willReturn(LogLevel.DEBUG);
// when
HtmlEmail email = sendMailSsl.initializeMail("recipient@example.com");
// then
assertThat(email, not(nullValue()));
assertThat(email.getToAddresses(), hasSize(1));
assertThat(email.getToAddresses().get(0).getAddress(), equalTo("recipient@example.com"));
assertThat(email.getFromAddress().getAddress(), equalTo(senderAccount));
assertThat(email.getFromAddress().getPersonal(), equalTo(senderName));
assertThat(email.getHostName(), equalTo(smtpHost));
assertThat(email.getSmtpPort(), equalTo("465"));
}
Aggregations