This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
additional changes to non-senate user activation, including email aut…
…h and registration
- Loading branch information
Jared Williams
committed
Jan 18, 2011
1 parent
723f49a
commit 482d008
Showing
9 changed files
with
305 additions
and
44 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ target/ | |
src/main/webapp/WEB-INF/lib/ | ||
src/main/webapp/WEB-INF/config.xml | ||
src/main/webapp/img/avatars | ||
*.properties |
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
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
86 changes: 86 additions & 0 deletions
86
src/main/java/gov/nysenate/opendirectory/utils/Mailer.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,86 @@ | ||
package gov.nysenate.opendirectory.utils; | ||
|
||
import gov.nysenate.opendirectory.models.ExternalPerson; | ||
|
||
import java.util.Date; | ||
import java.util.Properties; | ||
import java.util.StringTokenizer; | ||
|
||
import javax.mail.Message; | ||
import javax.mail.PasswordAuthentication; | ||
import javax.mail.Session; | ||
import javax.mail.Transport; | ||
import javax.mail.internet.InternetAddress; | ||
import javax.mail.internet.MimeMessage; | ||
|
||
public class Mailer { | ||
private static final String SMTP_HOST_NAME = Resource.get("hostname"); | ||
|
||
private static final String SMTP_PORT = Resource.get("port"); | ||
|
||
private static final String SMTP_ACCOUNT_USER = Resource.get("user"); | ||
private static final String SMTP_ACCOUNT_PASS = Resource.get("pass"); | ||
|
||
public static void sendMail(String to, String subject, String message, String from, String fromDisplay) throws Exception { | ||
Properties props = new Properties(); | ||
props.put("mail.smtp.host", SMTP_HOST_NAME); | ||
props.put("mail.smtp.auth", "true"); | ||
props.put("mail.debug", "true"); | ||
props.put("mail.smtp.port", SMTP_PORT); | ||
props.put("mail.smtp.starttls.enable","false"); | ||
props.put("mail.smtp.socketFactory.port", SMTP_PORT); | ||
props.put("mail.smtp.socketFactory.fallback", "false"); | ||
props.put("mail.smtp.ssl.enable","false"); | ||
|
||
Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication(SMTP_ACCOUNT_USER, SMTP_ACCOUNT_PASS);}}); | ||
session.setDebug(false); | ||
Message msg = new MimeMessage(session); | ||
InternetAddress addressFrom = new InternetAddress(from); | ||
addressFrom.setPersonal(fromDisplay); | ||
msg.setFrom(addressFrom); | ||
|
||
|
||
StringTokenizer st = new StringTokenizer (to,","); | ||
|
||
InternetAddress[] rcps = new InternetAddress[st.countTokens()]; | ||
int idx = 0; | ||
|
||
while (st.hasMoreTokens()) | ||
{ | ||
InternetAddress addressTo = new InternetAddress(st.nextToken()); | ||
rcps[idx++] = addressTo; | ||
|
||
} | ||
|
||
msg.setRecipients(Message.RecipientType.TO,rcps); | ||
|
||
msg.setSubject(subject); | ||
msg.setContent(message, "text/html"); | ||
Transport.send(msg); | ||
} | ||
|
||
public static void sendExternalAuthorizationMail(ExternalPerson person) { | ||
String authUrl = "http://directory.nysenate.gov/external/auth?email=" + person.getEmail() + | ||
"&key=" + person.getAuthorizationHash(); | ||
|
||
String to = person.getEmail(); | ||
String subject = "Authorize your NYSS OpenDirectory account"; | ||
String message = "Hello " + person.getFirstName() + ", <br/><br/>" + | ||
"It appears that you signed up to view the NYSS OpenDirectory, " + | ||
"in order to finalize this subscription you must click <a href\"" + authUrl + "\">here<a/> or open the following url: <br/><br/>" + | ||
authUrl + "<br/><br/>" + | ||
"If you have any questions please <a href=\"http://www.nysenate.gov/contact\">contact us</a>.<br/><br/>"; | ||
|
||
String from = "OpenDirectory@nysenate.gov"; | ||
String fromDisplay = "NYSS OpenDirectory"; | ||
|
||
try { | ||
sendMail(to, subject, message, from, fromDisplay); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} |
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
Oops, something went wrong.