Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Email functionality #2

Merged
merged 4 commits into from
Aug 19, 2024
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 @@ -71,7 +71,8 @@ private void sendEmailSync(String to, String subject, String content, boolean is
try {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, isMultipart, StandardCharsets.UTF_8.name());
message.setTo(to);
message.setFrom(jHipsterProperties.getMail().getFrom());
String SenderMail = "MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net";
message.setFrom(SenderMail);
message.setSubject(subject);
message.setText(content, isHtml);
javaMailSender.send(mimeMessage);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/.h2.server.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#H2 Server Properties
#Wed Aug 14 23:11:21 SGT 2024
#Sun Aug 18 23:12:35 SGT 2024
0=JHipster H2 (Disk)|org.h2.Driver|jdbc\:h2\:file\:./target/h2db/db/scaleup|scaleup
webAllowOthers=true
webPort=8092
Expand Down
20 changes: 16 additions & 4 deletions src/main/resources/config/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,23 @@ spring:
liquibase:
# Remove 'faker' if you do not want the sample data to be loaded automatically
contexts: dev, faker
# mail:
# host: localhost
# port: 25
# username:
# password:
mail:
host: localhost
port: 25
username:
password:
host: smtp.mailersend.net
port: 587
username: MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net
password: zTuZ0pxazgHfOWPK
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
messages:
cache-duration: PT1S # 1 second, see the ISO 8601 standard
thymeleaf:
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ management:
enabled: true
health:
mail:
enabled: false # When using the MailService, configure an SMTP server and set this to true
enabled: true # When using the MailService, configure an SMTP server and set this to true
prometheus:
metrics:
export:
Expand Down
16 changes: 8 additions & 8 deletions src/test/java/com/teamsixnus/scaleup/service/MailServiceIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testSendEmail() throws Exception {
MimeMessage message = messageCaptor.getValue();
assertThat(message.getSubject()).isEqualTo("testSubject");
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent()).isInstanceOf(String.class);
assertThat(message.getContent()).hasToString("testContent");
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8");
Expand All @@ -82,7 +82,7 @@ void testSendHtmlEmail() throws Exception {
MimeMessage message = messageCaptor.getValue();
assertThat(message.getSubject()).isEqualTo("testSubject");
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent()).isInstanceOf(String.class);
assertThat(message.getContent()).hasToString("testContent");
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
Expand All @@ -99,7 +99,7 @@ void testSendMultipartEmail() throws Exception {
part.writeTo(aos);
assertThat(message.getSubject()).isEqualTo("testSubject");
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent()).isInstanceOf(Multipart.class);
assertThat(aos).hasToString("\r\ntestContent");
assertThat(part.getDataHandler().getContentType()).isEqualTo("text/plain; charset=UTF-8");
Expand All @@ -116,7 +116,7 @@ void testSendMultipartHtmlEmail() throws Exception {
part.writeTo(aos);
assertThat(message.getSubject()).isEqualTo("testSubject");
assertThat(message.getAllRecipients()[0]).hasToString("john.doe@example.com");
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent()).isInstanceOf(Multipart.class);
assertThat(aos).hasToString("\r\ntestContent");
assertThat(part.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
Expand All @@ -133,7 +133,7 @@ void testSendEmailFromTemplate() throws Exception {
MimeMessage message = messageCaptor.getValue();
assertThat(message.getSubject()).isEqualTo("test title");
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent().toString()).isEqualToNormalizingNewlines("<html>test title, http://127.0.0.1:8080, john</html>\n");
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Expand All @@ -148,7 +148,7 @@ void testSendActivationEmail() throws Exception {
verify(javaMailSender).send(messageCaptor.capture());
MimeMessage message = messageCaptor.getValue();
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent().toString()).isNotEmpty();
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Expand All @@ -163,7 +163,7 @@ void testCreationEmail() throws Exception {
verify(javaMailSender).send(messageCaptor.capture());
MimeMessage message = messageCaptor.getValue();
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent().toString()).isNotEmpty();
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Expand All @@ -178,7 +178,7 @@ void testSendPasswordResetMail() throws Exception {
verify(javaMailSender).send(messageCaptor.capture());
MimeMessage message = messageCaptor.getValue();
assertThat(message.getAllRecipients()[0]).hasToString(user.getEmail());
assertThat(message.getFrom()[0]).hasToString(jHipsterProperties.getMail().getFrom());
assertThat(message.getFrom()[0]).hasToString("MS_hwQpFm@trial-k68zxl2o29egj905.mlsender.net");
assertThat(message.getContent().toString()).isNotEmpty();
assertThat(message.getDataHandler().getContentType()).isEqualTo("text/html;charset=UTF-8");
}
Expand Down
Loading