-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dd0c11
commit 529f7b6
Showing
3 changed files
with
101 additions
and
6 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package net.qldarch.message; | ||
|
||
import javax.mail.Authenticator; | ||
import javax.mail.PasswordAuthentication; | ||
import java.util.Properties; | ||
|
||
import javax.inject.Inject; | ||
|
@@ -25,6 +27,16 @@ public class MessageContact { | |
|
||
@Inject @Cfg("smtp.host") | ||
private String smtpHost; | ||
@Inject @Cfg("smtp.port") | ||
private String smtpPort; | ||
@Inject @Cfg("smtp.tls") | ||
private String smtptls; | ||
@Inject @Cfg("smtp.auth") | ||
private String smtpAuth; | ||
@Inject @Cfg("email.username") | ||
private String username; | ||
@Inject @Cfg("email.password") | ||
private String password; | ||
|
||
public MessageContactResponse send(String content, String senderName, String from, boolean newsletter) { | ||
try { | ||
|
@@ -33,7 +45,25 @@ public MessageContactResponse send(String content, String senderName, String fro | |
.replace("\n", "<br/>"); | ||
final Properties properties = new Properties(); | ||
properties.setProperty("mail.smtp.host", smtpHost); | ||
Session session = Session.getDefaultInstance(properties); | ||
properties.setProperty("mail.smtp.port", smtpPort); | ||
properties.setProperty("mail.smtp.auth", smtpAuth); | ||
properties.setProperty("mail.smtp.starttls.enable", smtptls); | ||
properties.put("mail.smtp.ssl.protocols", "TLSv1.2"); | ||
properties.put("mail.smtp.ssl.trust", smtpHost); | ||
|
||
//char[] passwordArray = password.toCharArray(); | ||
Session session; | ||
|
||
if(smtpAuth.equalsIgnoreCase("true")) { | ||
session = Session.getInstance(properties, new Authenticator() { | ||
@Override | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication(username, password); | ||
} | ||
}); | ||
}else { | ||
session = Session.getDefaultInstance(properties); | ||
} | ||
MimeMessage message = new MimeMessage(session); | ||
users.all().forEach(user -> { | ||
if(user.isContact()) { | ||
|
@@ -44,7 +74,8 @@ public MessageContactResponse send(String content, String senderName, String fro | |
} | ||
} | ||
}); | ||
message.setFrom(new InternetAddress("[email protected]")); | ||
//message.setFrom(new InternetAddress("[email protected]")); | ||
message.setFrom(new InternetAddress(username)); | ||
message.setSubject(subject); | ||
message.setContent(msg, "text/html; charset=utf-8"); | ||
Transport.send(message); | ||
|
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 |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
import static org.apache.commons.lang3.StringUtils.isBlank; | ||
|
||
import javax.mail.Authenticator; | ||
import javax.mail.PasswordAuthentication; | ||
import java.util.Properties; | ||
|
||
import javax.inject.Inject; | ||
|
@@ -39,6 +41,16 @@ public class SignUp { | |
|
||
@Inject @Cfg("smtp.host") | ||
private String smtpHost; | ||
@Inject @Cfg("smtp.port") | ||
private String smtpPort; | ||
@Inject @Cfg("smtp.tls") | ||
private String smtptls; | ||
@Inject @Cfg("smtp.auth") | ||
private String smtpAuth; | ||
@Inject @Cfg("email.username") | ||
private String username; | ||
@Inject @Cfg("email.password") | ||
private String password; | ||
|
||
private String activationCode() { | ||
return rstr.next(); | ||
|
@@ -52,10 +64,31 @@ private void sendActivationEmail(final String email, final long id, final String | |
try { | ||
final Properties properties = new Properties(); | ||
properties.setProperty("mail.smtp.host", smtpHost); | ||
Session session = Session.getDefaultInstance(properties); | ||
properties.setProperty("mail.smtp.port", smtpPort); | ||
properties.setProperty("mail.smtp.auth", smtpAuth); | ||
properties.setProperty("mail.smtp.starttls.enable", smtptls); | ||
properties.put("mail.smtp.ssl.protocols", "TLSv1.2"); | ||
properties.put("mail.smtp.ssl.trust", smtpHost); | ||
|
||
//char[] passwordArray = password.toCharArray(); | ||
Session session; | ||
|
||
if(smtpAuth.equalsIgnoreCase("true")) { | ||
session = Session.getInstance(properties, new Authenticator() { | ||
@Override | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication(username, password); | ||
} | ||
}); | ||
}else { | ||
session = Session.getDefaultInstance(properties); | ||
} | ||
|
||
//Session session = Session.getDefaultInstance(properties); | ||
MimeMessage message = new MimeMessage(session); | ||
message.addRecipient(Message.RecipientType.TO, new InternetAddress(email)); | ||
message.setFrom(new InternetAddress("[email protected]")); | ||
//message.setFrom(new InternetAddress("[email protected]")); | ||
message.setFrom(new InternetAddress(username)); | ||
message.setSubject("Qldarch Account Activation"); | ||
final String content = "Click <a href=\"%sws/account/activate?id=%s&code=%s\">here" | ||
+ "</a> to activate your account."; | ||
|
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
package net.qldarch.security; | ||
|
||
import javax.mail.Authenticator; | ||
import javax.mail.PasswordAuthentication; | ||
import java.util.Properties; | ||
|
||
import javax.annotation.Nullable; | ||
|
@@ -40,6 +42,16 @@ public class WsResetPassword { | |
@Inject | ||
@Cfg("smtp.host") | ||
private String smtpHost; | ||
@Inject @Cfg("smtp.port") | ||
private String smtpPort; | ||
@Inject @Cfg("smtp.tls") | ||
private String smtptls; | ||
@Inject @Cfg("smtp.auth") | ||
private String smtpAuth; | ||
@Inject @Cfg("email.username") | ||
private String username; | ||
@Inject @Cfg("email.password") | ||
private String password; | ||
|
||
private String encrypt(String s) { | ||
final DefaultPasswordService passwordService = new DefaultPasswordService(); | ||
|
@@ -79,10 +91,29 @@ private boolean send(String content, User user) { | |
String msg = (content).replace("\n", "<br/>"); | ||
final Properties properties = new Properties(); | ||
properties.setProperty("mail.smtp.host", smtpHost); | ||
Session session = Session.getDefaultInstance(properties); | ||
properties.setProperty("mail.smtp.port", smtpPort); | ||
properties.setProperty("mail.smtp.auth", smtpAuth); | ||
properties.setProperty("mail.smtp.starttls.enable", smtptls); | ||
properties.put("mail.smtp.ssl.protocols", "TLSv1.2"); | ||
properties.put("mail.smtp.ssl.trust", smtpHost); | ||
|
||
//char[] passwordArray = password.toCharArray(); | ||
Session session; | ||
|
||
if(smtpAuth.equalsIgnoreCase("true")) { | ||
session = Session.getInstance(properties, new Authenticator() { | ||
@Override | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication(username, password); | ||
} | ||
}); | ||
}else { | ||
session = Session.getDefaultInstance(properties); | ||
} | ||
|
||
MimeMessage message = new MimeMessage(session); | ||
message.addRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail())); | ||
message.setFrom(new InternetAddress("[email protected]")); | ||
message.setFrom(new InternetAddress(username)); | ||
message.setSubject("Qldarch Password Reset"); | ||
message.setContent(msg, "text/html; charset=utf-8"); | ||
Transport.send(message); | ||
|