public void sendEMailToUser(ICFSecuritySecUserObj toUser, String msgSubject, String msgBody) throws IOException, MessagingException, NamingException { final String S_ProcName = "sendEMailToUser"; Properties props = System.getProperties(); Context ctx = new InitialContext(); String smtpEmailFrom = (String) ctx.lookup("java:comp/env/CFInternet25SmtpEmailFrom"); if ((smtpEmailFrom == null) || (smtpEmailFrom.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException( getClass(), S_ProcName, 0, "JNDI lookup for CFInternet25SmtpEmailFrom"); } smtpUsername = (String) ctx.lookup("java:comp/env/CFInternet25SmtpUsername"); if ((smtpUsername == null) || (smtpUsername.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException( getClass(), S_ProcName, 0, "JNDI lookup for CFInternet25SmtpUsername"); } smtpPassword = (String) ctx.lookup("java:comp/env/CFInternet25SmtpPassword"); if ((smtpPassword == null) || (smtpPassword.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException( getClass(), S_ProcName, 0, "JNDI lookup for CFInternet25SmtpPassword"); } Session emailSess = Session.getInstance( props, new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUsername, smtpPassword); } }); MimeMessage msg = new MimeMessage(emailSess); msg.setFrom(new InternetAddress(smtpEmailFrom)); InternetAddress mailTo[] = InternetAddress.parse(toUser.getRequiredEMailAddress(), false); msg.setRecipient(Message.RecipientType.TO, mailTo[0]); msg.setSubject((msgSubject != null) ? msgSubject : "No subject"); msg.setSentDate(new Date()); msg.setContent(msgBody, "text/html"); msg.saveChanges(); Transport.send(msg); }
public void setUpdatedBy(ICFSecuritySecUserObj value) { updatedBy = value; if (value != null) { getBuff().setUpdatedByUserId(value.getRequiredSecUserId()); } }