Merge pull request #199 from hsombini/mailAddressField

Email address field for email servers that does not use email as the …
This commit is contained in:
Gabriele C 2017-01-08 17:40:05 +01:00 committed by GitHub
commit ef5dfabd9c
4 changed files with 40 additions and 5 deletions

View File

@ -125,7 +125,10 @@ public class SendMailSSL {
@VisibleForTesting
HtmlEmail initializeMail(String emailAddress) throws EmailException {
String senderMail = settings.getProperty(EmailSettings.MAIL_ACCOUNT);
String senderMail = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_ADDRESS))
? settings.getProperty(EmailSettings.MAIL_ACCOUNT)
: settings.getProperty(EmailSettings.MAIL_ADDRESS);
String senderName = StringUtils.isEmpty(settings.getProperty(EmailSettings.MAIL_SENDER_NAME))
? senderMail
: settings.getProperty(EmailSettings.MAIL_SENDER_NAME);
@ -139,7 +142,7 @@ public class SendMailSSL {
email.addTo(emailAddress);
email.setFrom(senderMail, senderName);
email.setSubject(settings.getProperty(EmailSettings.RECOVERY_MAIL_SUBJECT));
email.setAuthentication(senderMail, mailPassword);
email.setAuthentication(settings.getProperty(EmailSettings.MAIL_ACCOUNT), mailPassword);
setPropertiesForPort(email, port);
return email;

View File

@ -27,6 +27,10 @@ public class EmailSettings implements SettingsHolder {
public static final Property<String> MAIL_PASSWORD =
newProperty("Email.mailPassword", "");
@Comment("Email address, fill when mailAccount is not the email address of the account")
public static final Property<String> MAIL_ADDRESS =
newProperty("Email.mailAddress", "");
@Comment("Custom sender name, replacing the mailAccount name in the email")
public static final Property<String> MAIL_SENDER_NAME =
newProperty("Email.mailSenderName", "");

View File

@ -200,8 +200,8 @@ public class SendMailSSLTest {
given(settings.getProperty(EmailSettings.SMTP_PORT)).willReturn(465);
String smtpHost = "mail.example.com";
given(settings.getProperty(EmailSettings.SMTP_HOST)).willReturn(smtpHost);
String senderMail = "sender@example.org";
given(settings.getProperty(EmailSettings.MAIL_ACCOUNT)).willReturn(senderMail);
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);
@ -212,7 +212,33 @@ public class SendMailSSLTest {
assertThat(email, not(nullValue()));
assertThat(email.getToAddresses(), hasSize(1));
assertThat(email.getToAddresses().get(0).getAddress(), equalTo("recipient@example.com"));
assertThat(email.getFromAddress().getAddress(), equalTo(senderMail));
assertThat(email.getFromAddress().getAddress(), equalTo(senderAccount));
assertThat(email.getFromAddress().getPersonal(), equalTo(senderName));
assertThat(email.getHostName(), equalTo(smtpHost));
assertThat(email.getSmtpPort(), equalTo("465"));
}
@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"));

View File

@ -318,6 +318,8 @@ Email:
mailAccount: ''
# Email account password
mailPassword: ''
# Email address, fill when mailAccount is not email address of the account
mailAddress: ''
# Custom SenderName, that replace the mailAccount name in the email
mailSenderName: ''
# Random password length