Mercurial Hosting > nabble
diff src/nabble/view/lib/ChangeEmailMail.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/nabble/view/lib/ChangeEmailMail.java Thu Mar 21 19:15:52 2019 -0600 @@ -0,0 +1,82 @@ + +package nabble.view.lib; + +import fschmidt.util.mail.AlternativeMultipartContent; +import fschmidt.util.mail.Content; +import fschmidt.util.mail.Mail; +import fschmidt.util.mail.MailAddress; +import fschmidt.util.mail.MailException; +import fschmidt.util.mail.MailHome; +import fschmidt.util.mail.PlainTextContent; +import fschmidt.util.mail.TextContent; +import nabble.model.ModelHome; +import nabble.model.Site; + +import java.io.PrintWriter; +import java.io.StringWriter; + + +public class ChangeEmailMail { + + public static void send(Site site, String username, String oldEmail, String newEmail, String url) { + StringWriter content = new StringWriter(); + PrintWriter out = new PrintWriter(content); + // text part + + out.print( "\r\nDear " ); + out.print( (username) ); + out.print( ",\r\n\r\nYou or the administrator of \"" ); + out.print( (site.getRootNode().getSubject()) ); + out.print( "\" wants to change the email address of your user account.\r\nUsername: " ); + out.print( (username) ); + out.print( "\r\nOld email address: " ); + out.print( (oldEmail) ); + out.print( "\r\nNew email address: " ); + out.print( (newEmail) ); + out.print( "\r\n\r\nPlease click on the link below if you want to confirm this change:\r\n" ); + out.print( (url) ); + out.print( "\r\n\r\nIf you didn't request this email or have no idea why you received it, please ignore it.\r\n\r\nRegards,\r\nThe Nabble Team\r\n" ); + + out.flush(); + String text = content.toString(); + + content.getBuffer().setLength(0); + // aol part + + out.print( "\r\nDear " ); + out.print( (username) ); + out.print( ",\r\n\r\nYou or the administrator of \"" ); + out.print( (site.getRootNode().getSubject()) ); + out.print( "\" wants to change the email address of your user account.\r\nUsername: " ); + out.print( (username) ); + out.print( "\r\nOld email address: " ); + out.print( (oldEmail) ); + out.print( "\r\nNew email address: " ); + out.print( (newEmail) ); + out.print( "\r\n\r\nPlease click on the link below if you want to confirm this change:\r\n<a href=\"" ); + out.print( (url) ); + out.print( "\">" ); + out.print( (url) ); + out.print( "</a>\r\n\r\nIf you didn't request this email or have no idea why you received it, please ignore it.\r\n\r\nRegards,\r\nThe Nabble Team\r\n" ); + + out.flush(); + String aol = content.toString(); + + out.close(); + try { + Mail mail = MailHome.newMail(); + mail.setFrom( new MailAddress(ModelHome.noReply) ); + mail.setTo( new MailAddress(newEmail) ); + mail.setSubject( "Email Change" ); + mail.setContent( new AlternativeMultipartContent(new Content[]{ + new PlainTextContent(text), + new TextContent("x-aol",aol), + }) ); + ModelHome.send(mail); + } catch(MailException e) { + throw new RuntimeException(e); + } + } + +} +