public void sendMail ( String to , String subject , String content ) throws MessagingException { Properties props = new Properties ( ) ; props . put ( "mail.smtp.user" , emailConfg . getUser ( ) ) ; props . put ( "mail.smtp.host" , emailConfg . getHost ( ) ) ; props . put ( "mail.smtp.port" , emailConfg . getPort ( ) ) ; props . put ( "mail.smtp.starttls.enable" , "true" ) ; props . put ( "mail.smtp.debug" , emailConfg . getDebug ( ) ) ; props . put ( "mail.smtp.auth" , emailConfg . getAuth ( ) ) ; props . put ( "mail.smtp.ssl.trust" , emailConfg . host ) ; SMTPAuthenticator auth = new SMTPAuthenticator ( emailConfg . getUser ( ) , ( String ) secret . get ( SecretConstants . EMAIL_PASSWORD ) ) ; Session session = Session . getInstance ( props , auth ) ; MimeMessage message = new MimeMessage ( session ) ; message . setFrom ( new InternetAddress ( emailConfg . getUser ( ) ) ) ; message . addRecipient ( Message . RecipientType . TO , new InternetAddress ( to ) ) ; message . setSubject ( subject ) ; message . setContent ( content , "text/html" ) ; // Send message Transport . send ( message ) ; if ( logger . isInfoEnabled ( ) ) logger . info ( "An email has been sent to " + to + " with subject " + subject ) ; }
Send email with a string content .