Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > pls help me when i sent mail, it vil sending twice instead of once ,am using java.mail,am sending my code....

Reply
Thread Tools

pls help me when i sent mail, it vil sending twice instead of once ,am using java.mail,am sending my code....

 
 
shailajabtech@gmail.com
Guest
Posts: n/a
 
      09-28-2006
Every thing is working fine but it sending message twice instead of
once.

in the Forget.jsp page am accepting username or email

<struts-config.xml>
<form-beans>
<form-bean name="forgotUname"
type="org.apache.struts.validator.DynaValidatorFor m">
<form-property name="userName" type="java.lang.String" />
<form-property name="email" type="java.lang.String" />
</form-bean>
</form-beans>
<action-mappings>
<action path="/Forgot" name="forgotUname"
type="org.springframework.web.struts.DelegatingAct ionProxy"
parameter="operation"
input="/Forget.jsp" scope="request" validate="false">
<forward name="PasswordSuccess" path="/PasswordSuccess.jsp" />
<forward name="HomePage" path="/Forget.jsp"/>
<forward name="Index" path="/index.jsp" />

</action>
</action-mappings>

</struts-config.xml>

ForgotUnamePwdAction:

package com.infistech.eservices.apps.hr.actions;

import com.infistech.eservices.apps.hr.utils.Constants;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.DynaValidatorForm;

import com.infistech.eservices.apps.hr.model.User;
import com.infistech.eservices.apps.hr.service.UserManage r;

public class ForgotUnamePwdAction extends EservicesBaseAction {
private UserManager userManager;

public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}

private static Logger log =
Logger.getLogger("ForgotUnamePwdAction.class");

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
DynaValidatorForm forgot = (DynaValidatorForm) form;
log.debug("In the execute mtd");
if (validationSuccessful(request, mapping, forgot)) {

String userName = forgot.getString("userName");

String toAddress = forgot.getString("email");

String password = null;
String uname = null;
String fromAddress = Constants.EMAILADDR_ORGANIZER;

if (toAddress == null && userName == null) {
ActionMessages msg = new ActionMessages();
ActionMessage msg1 = new ActionMessage("forgot.failed");
msg.add("message", msg1);
saveMessages(request, msg);
return mapping.findForward("HomePage");

}

if (toAddress != null && toAddress.equals("") != true) {
User user = null;
log.debug("EMAILID:" + toAddress);
try {
user = userManager.getUserByEmail(toAddress);

log.debug("USEROBJECT" + user);
if (user == null) {
ActionMessages msg = new ActionMessages();
ActionMessage msg1 = new ActionMessage("email.db");
msg.add("message", msg1);
saveMessages(request, msg);
return mapping.findForward("HomePage");

}

password = user.getPassword();
uname = user.getUserName();
String firstName = user.getFirstName();

String content = "Hi "
+ firstName
+ ",\n\n Here are your login details for your My Assurejobs
Account.\n\n UserName: "
+ uname + "\n Password: " + password
+ "\n\n\n Best Regards,\n AssureJobs Team";

log.debug("in first cond");
Properties props = new Properties();
props.put("mail.smtp.host", "192.168.1.2");
Session ses = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(ses);
msg.setFrom(new InternetAddress(fromAddress));

msg.setRecipients(Message.RecipientType.TO, InternetAddress
.parse(toAddress, false));

msg.setSubject("hi " + firstName
+ ", AssureJobs Login Details");
msg.setText(content);

Transport.send(msg);
return mapping.findForward("PasswordSuccess");
} catch (Exception e) {
ActionMessages msg = new ActionMessages();
ActionMessage msg1 = new ActionMessage("prob.db");
msg.add("message", msg1);
saveMessages(request, msg);

}

}

else if (userName != null && userName.equals("") != true) {
log.debug("INTHE IF ELSE CONDITION USERNAME" + userName);
log.debug("getting the user obj from Manager");
User user = null;
try {
user = userManager.getUserByUserName(userName);
if (user == null) {
ActionMessages msg = new ActionMessages();
ActionMessage msg1 = new ActionMessage("user.db");
msg.add("message", msg1);
saveMessages(request, msg);
return mapping.findForward("HomePage");

}

log.debug("USEROBJ" + user);

String password1 = user.getPassword();
String email = user.getEmail();
String firstName = user.getFirstName();
log.debug("FIRSTNAME:" + firstName);
String content = "Hi "
+ firstName
+ ",\n\n Here are your login details for your My Assurejobs
Account\n\n Password: "
+ password1
+ "\n\n\n Best Regards,\n AssureJobs Team";

Properties props = new Properties();
props.put("mail.smtp.host", "192.168.1.2");
Session ses = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(ses);
msg.setFrom(new InternetAddress(fromAddress));

msg.setRecipients(Message.RecipientType.TO, InternetAddress
.parse(email, false));

msg.setSubject("hi " + firstName
+ ", AssureJobs Login Details");
msg.setText(content);

Transport.send(msg);
return mapping.findForward("PasswordSuccess");
} catch (Exception e) {
log.debug("Unble to find the user with that username" + e);
ActionMessages msg = new ActionMessages();
ActionMessage msg1 = new ActionMessage("prob.db");
msg.add("message", msg1);
saveMessages(request, msg);
return mapping.findForward("HomePage");

}

}
ActionMessages msg = new ActionMessages();
ActionMessage msg1 = new ActionMessage("forgot.failed");
msg.add("message", msg1);
saveMessages(request, msg);
return mapping.findForward("HomePage");
}

else
return mapping.findForward("HomePage");
}

private boolean validationSuccessful(HttpServletRequest request,
ActionMapping mapping, ActionForm form)

{
ActionMessages errors = form.validate(mapping, request);
if (!errors.isEmpty()) {
saveErrors(request, errors);
if (log.isDebugEnabled())
log.debug("it return false");
return false;
} else {
if (log.isDebugEnabled())
log.debug("it returns true");
return true;
}
}
}



Here am using hibernate concepts for backend.

after sending mail it vil go to the success page.

every thing is working fine but it sending message twice instead of
once.



Thanks in Advance.
ShailajaD.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
URGENT - Pls help...pls recommend - laptop purchase irfansmith@gmail.com Computer Information 2 08-15-2008 11:34 PM
voipfone + Draytek 2600V: Keypad tone sent twice (using conferencingsystem...) damn-it UK VOIP 0 02-19-2007 10:51 PM
Problem with prints twice instead of once. MNQ C Programming 8 02-06-2004 01:44 PM
c#:only put "using blah.blah.blah" once instead of every page? evolve ASP .Net 2 11-02-2003 04:12 AM
pls, help.. i need a number..pls olabanji timothy MCSE 7 09-10-2003 04:02 PM



Advertisments