
//Recover.java
//Author: Ogbole A. Israel
//this method sends the password.
public void postMail(String smtpsrv, String recipients, String subject,String message, String from) throws MessagingException {
//TODO implement postMail
boolean debug = false;
System.out.println("got here 1");
Properties props = new Properties();
System.out.println("got here 2");
props.put("mail.smtp.host", smtpsrv);
System.out.println("got here 3");
Session session = Session.getDefaultInstance(props, null);
System.out.println("got here 4");
session.setDebug(debug);
System.out.println("got here 5");
// create a message
Message msg = new MimeMessage(session);
System.out.println("got here 6");
InternetAddress addressFrom = new InternetAddress(from);
System.out.println("got here 7");
msg.setFrom(addressFrom);
System.out.println("got here 8");
InternetAddress addressTo = new InternetAddress(recipients);
System.out.println("got here 9");
msg.setRecipient(RecipientType.TO, addressTo);
System.out.println("got here 10");
msg.setSubject(subject);
System.out.println("got here 11");
msg.setContent(message, "text/html;charset=utf-8");
System.out.println("got here 12");
Transport.send(msg);
System.out.println("got here 13");
}
//this method retrives the password. asuming the email address is primary key in the user table
public String getThePassword(String id) {
//TODO implement getThePassword
UserloginLocal userllocal = null;
try{
userllocal = userloginlhome.findByPrimaryKey(id);
}catch(Exception ex){
System.out.println("Error occured in gettting th pasword " +ex.getMessage());
}
return userllocal.getPassword();
}
No comments:
Post a Comment