public void sendResetPassword( String email, String password ) { StringBuilder body = new StringBuilder(); body.append( "Your password has been reset. Your new password is: " ); body.append( password ); MailRequest request = nexusEmailer.getDefaultMailRequest( "Nexus: User account notification.", body.toString() ); request.getToAddresses().add( new Address( email ) ); nexusEmailer.sendMail( request ); } }
public String toString() { if ( StringUtils.isEmpty( getPersonal() ) ) { return "<" + getMailAddress() + ">"; } else { return "\"" + getPersonal() + "\" <" + getMailAddress() + ">"; } } }
protected void setRecipientsFromList(String encoding, MimeMessage message, RecipientType type, List<Address> addresses) throws MessagingException, UnsupportedEncodingException { if (addresses == null || addresses.size() == 0) { return; } InternetAddress[] adrs = new InternetAddress[addresses.size()]; for (int i = 0; i < addresses.size(); i++) { adrs[i] = addresses.get(i).getInternetAddress(encoding); } message.setRecipients(type, adrs); }
/** * Performs a formal validation of an e-mail address. * * @param address string representing an e-mail address. * @throws IllegalArgumentException */ public static void validateAddress( final String address ) throws IllegalArgumentException { if ( Strings.isEmpty( address ) ) { throw new IllegalArgumentException( "E-mail address cannot be empty!" ); } validateAddress( new Address( address ) ); }
/** * Performs a formal validation of an Address. * * @param address the address to validate * @throws IllegalArgumentException */ public static void validateAddress( final Address address ) throws IllegalArgumentException { if ( address == null ) { throw new IllegalArgumentException( "E-mail address is null!" ); } try { // this method perform validation too using Java Mail. address.getInternetAddress( EMailer.DEFAULT_ENCODING ); } catch ( AddressException e ) { throw new IllegalArgumentException( "Invalid e-mail address: " + address.toString(), e ); } catch ( UnsupportedEncodingException e ) { // huh? Emailer.DEFAULT_ENCODING not supported? throw new IllegalStateException( "EMailer needs a JVM that supports " + EMailer.DEFAULT_ENCODING + " encoding!" ); } } }
String systemName = settings.getString(Mailer.Setting.mail_systemName, "Fathom"); String systemAddress = settings.getString(Mailer.Setting.mail_systemAddress, "fathom@gitblit.com"); request.setFrom(new Address(systemAddress, systemName)); message.setSender(request.getSender().getInternetAddress(request.getEncoding())); message.setFrom(request.getFrom().getInternetAddress(request.getEncoding())); .getInternetAddress(request.getEncoding())});
public void setSMTPSystemEmailAddress( Address adr ) { getCurrentConfiguration( true ).setSystemEmailAddress( adr.getMailAddress() ); }
public Address( final String mailAddress, final String personal ) throws IllegalArgumentException { this.mailAddress = mailAddress; this.personal = personal; validateAddress( this ); }
String systemName = settings.getString(Mailer.Setting.mail_systemName, "Fathom"); String systemAddress = settings.getString(Mailer.Setting.mail_systemAddress, "fathom@gitblit.com"); request.setFrom(new Address(systemAddress, systemName)); message.setSender(request.getSender().getInternetAddress(request.getEncoding())); message.setFrom(request.getFrom().getInternetAddress(request.getEncoding())); .getInternetAddress(request.getEncoding())});
public static SmtpSettings convert(NexusEmailer nexusEmailer) { if (nexusEmailer == null) { return null; } SmtpSettings result = new SmtpSettings(); result.setHost(nexusEmailer.getSMTPHostname()); result.setPort(nexusEmailer.getSMTPPort()); result.setSslEnabled(nexusEmailer.isSMTPSslEnabled()); result.setTlsEnabled(nexusEmailer.isSMTPTlsEnabled()); result.setUsername(nexusEmailer.getSMTPUsername()); if (!StringUtils.isEmpty(nexusEmailer.getSMTPPassword())) { result.setPassword(PASSWORD_PLACE_HOLDER); } result.setSystemEmailAddress(nexusEmailer.getSMTPSystemEmailAddress().getMailAddress()); return result; }
public void sendForgotUsername( String email, List<String> userIds ) { StringBuilder body = new StringBuilder(); body.append( "Your email is associated with the following Nexus User Id(s):\n " ); for ( String userId : userIds ) { body.append( "\n - \"" ); body.append( userId ); body.append( "\"" ); } MailRequest request = nexusEmailer.getDefaultMailRequest( "Nexus: User account notification.", body.toString() ); request.getToAddresses().add( new Address( email ) ); nexusEmailer.sendMail( request ); }
public String toString() { if ( Strings.isEmpty(getPersonal()) ) { return "<" + getMailAddress() + ">"; } else { return "\"" + getPersonal() + "\" <" + getMailAddress() + ">"; } }
public static SmtpSettings convert( NexusEmailer nexusEmailer ) { if ( nexusEmailer == null ) { return null; } SmtpSettings result = new SmtpSettings(); result.setHost( nexusEmailer.getSMTPHostname() ); result.setPort( nexusEmailer.getSMTPPort() ); result.setSslEnabled( nexusEmailer.isSMTPSslEnabled() ); result.setTlsEnabled( nexusEmailer.isSMTPTlsEnabled() ); result.setUsername( nexusEmailer.getSMTPUsername() ); if ( !StringUtils.isEmpty( nexusEmailer.getSMTPPassword() ) ) { result.setPassword( PASSWORD_PLACE_HOLDER ); } result.setSystemEmailAddress( nexusEmailer.getSMTPSystemEmailAddress().getMailAddress() ); return result; }
protected void setRecipientsFromList(String encoding, MimeMessage message, RecipientType type, List<Address> addresses) throws MessagingException, UnsupportedEncodingException { if (addresses == null || addresses.size() == 0) { return; } InternetAddress[] adrs = new InternetAddress[addresses.size()]; for (int i = 0; i < addresses.size(); i++) { adrs[i] = addresses.get(i).getInternetAddress(encoding); } message.setRecipients(type, adrs); }
public void sendNewUserCreated( String email, String userid, String password ) { StringBuilder body = new StringBuilder(); body.append( "User Account " ); body.append( userid ); body.append( " has been created. Another email will be sent shortly containing your password." ); MailRequest request = nexusEmailer.getDefaultMailRequest( "Nexus: New user account created.", body.toString() ); request.getToAddresses().add( new Address( email ) ); nexusEmailer.sendMail( request ); body = new StringBuilder(); body.append( "Your new password is " ); body.append( password ); request = nexusEmailer.getDefaultMailRequest( "Nexus: New user account created.", body.toString() ); request.getToAddresses().add( new Address( email ) ); nexusEmailer.sendMail( request ); }
public InternetAddress getInternetAddress( String encoding ) throws AddressException, UnsupportedEncodingException { InternetAddress adr = new InternetAddress( getMailAddress(), getPersonal(), encoding ); adr.validate(); return adr; }
protected void setRecipientsFromList( String encoding, MimeMessage message, RecipientType type, List<Address> addresses ) throws MessagingException, UnsupportedEncodingException { if ( addresses == null || addresses.size() == 0 ) { return; } InternetAddress[] adrs = new InternetAddress[addresses.size()]; for ( int i = 0; i < addresses.size(); i++ ) { adrs[i] = addresses.get( i ).getInternetAddress( encoding ); } message.setRecipients( type, adrs ); }
/** * {@inheritDoc} */ public void sendNexusTaskFailure( final String email, final String taskId, final String taskName, final Throwable cause ) { final StringBuilder body = new StringBuilder(); if ( taskId != null ) { body.append( String.format( "Task ID: %s", taskId ) ).append( "\n" ); } if ( taskName != null ) { body.append( String.format( "Task Name: %s", taskName ) ).append( "\n" ); } if ( cause != null ) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter( sw ); cause.printStackTrace( pw ); body.append( "Stack trace: " ).append( "\n" ).append( sw.toString() ); } MailRequest request = nexusEmailer.getDefaultMailRequest( "Nexus: Task execution failure", body.toString() ); request.getToAddresses().add( new Address( email ) ); nexusEmailer.sendMail( request ); }
public InternetAddress getInternetAddress( final String encoding ) throws AddressException, UnsupportedEncodingException { final InternetAddress adr = new InternetAddress( getMailAddress(), getPersonal(), encoding ); adr.validate(); return adr; }
protected void setRecipientsFromList( String encoding, MimeMessage message, RecipientType type, List<Address> addresses ) throws MessagingException, UnsupportedEncodingException { if ( addresses == null || addresses.size() == 0 ) { return; } InternetAddress[] adrs = new InternetAddress[addresses.size()]; for ( int i = 0; i < addresses.size(); i++ ) { adrs[i] = addresses.get( i ).getInternetAddress( encoding ); } message.setRecipients( type, adrs ); }