Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
public class EmailService implements ConsentLogger {

private static final int LOOKBACK_DELAY_HOURS = 24;

/**
* Friendly name shown as the sender of all outgoing SendGrid messages. Without it, the From
* header carries a bare address and mail clients typically display the local part instead -
* 'duos', for the production account.
*/
private static final String FROM_NAME = "DUOS";

@VisibleForTesting protected static int sendgridThrottleMessageCount = 500;
@VisibleForTesting protected static int sendgridThrottleResetTime = 60;
private final UserDAO userDAO;
Expand Down Expand Up @@ -80,7 +88,7 @@ public void sendMessage(MailMessage mailMessage, Integer userId)
String content = out.toString();
Mail message =
new Mail(
new Email(fromAccount),
new Email(fromAccount, FROM_NAME),
mailMessage.createSubject(),
new Email(mailMessage.toUser.getEmail()),
new Content("text/html", content));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class EmailServiceTest extends AbstractTestHelper {

private static final String SERVER_URL = "http://localhost:8000/#/";
private static final String FROM = "from@duos";
private static final String FROM_NAME = "DUOS";
private EmailService service;
@Mock private ElectionDAO electionDAO;
@Mock private UserDAO userDAO;
Expand Down Expand Up @@ -137,6 +138,7 @@ void testSendMessage() throws Exception {
verify(sendGridAPI).sendMessage(captor.capture(), eq(user.getEmail()));
var mail = captor.getValue();
assertEquals(FROM, mail.getFrom().getEmail());
assertEquals(FROM_NAME, mail.getFrom().getName());
assertEquals(
user.getEmail(), mail.getPersonalization().getFirst().getTos().getFirst().getEmail());
assertEquals(subject, mail.getSubject());
Expand Down
Loading