-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create SMTPService with proper configuration for sending magic link
- Loading branch information
Showing
3 changed files
with
55 additions
and
14 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
vcell-rest/src/main/java/org/vcell/restq/db/SMTPService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.vcell.restq.db; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import javax.mail.Message; | ||
import javax.mail.MessagingException; | ||
import javax.mail.Session; | ||
import javax.mail.Transport; | ||
import javax.mail.internet.AddressException; | ||
import javax.mail.internet.InternetAddress; | ||
import javax.mail.internet.MimeMessage; | ||
|
||
@ApplicationScoped | ||
public class SMTPService { | ||
|
||
@ConfigProperty(name = "vcell.smtp.hostName") | ||
String smtpHostName; | ||
|
||
@ConfigProperty(name = "vcell.smtp.port") | ||
String smtpPost; | ||
|
||
@ConfigProperty(name = "vcell.smtp.emailAddress") | ||
String smtpEmail; | ||
|
||
|
||
public void sendEmail(String emailAddress, String subject, String body) throws MessagingException { | ||
// Create a mail session | ||
java.util.Properties props = new java.util.Properties(); | ||
props.put("mail.smtp.host", smtpHostName); | ||
props.put("mail.smtp.port", "" + Integer.parseInt(smtpPost)); | ||
Session session = Session.getDefaultInstance(props, null); | ||
|
||
// Construct the message | ||
Message msg = new MimeMessage(session); | ||
msg.setFrom(new InternetAddress(smtpEmail)); | ||
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(emailAddress)); | ||
msg.setSubject(subject); | ||
msg.setText(body); | ||
|
||
// Send the message | ||
Transport.send(msg); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,5 +121,8 @@ quarkus.swagger-ui.always-include=true | |
%dev.quarkus.swagger-ui.oauth-use-pkce-with-authorization-code-grant=true | ||
%test.quarkus.swagger-ui.oauth-use-pkce-with-authorization-code-grant=false | ||
|
||
## VCell tests | ||
## VCell properties | ||
%dev,test.vcell.softwareVersion=8.0.0 | ||
vcell.smtp.hostName=smtp.cam.uchc.edu | ||
vcell.smtp.port=25 | ||
vcell.smtp.emailAddress=[email protected] |