f



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

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.DynaValidatorForm">
			<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.DelegatingActionProxy"
                           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.UserManager;

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.

0
9/28/2006 6:38:38 AM
comp.lang.java.programmer 52711 articles. 1 followers. Post Follow

0 Replies
1571 Views

Similar Articles

[PageSpeed] 31

Reply:

Similar Artilces:

I want to send a mail using mailx(unix) in java code
Hi All, I am trying to send a mail using shell script as for that java will be a bit bulkier , so I Am using mailx command of unix .. .. .. .. .. ------previous code---- .. .. .. Process proc; proc = Runtime.getRuntime().exec("mailx -s "+ msg +"'abc.xyz@gmail.com'"); }catch(IOException e) {System.out.println(" Error Occured "+e);} is there anything wrong with this coz I am getting an error msg like Error Occured java.io.IOException: CreateProcess: mailx -s Mismatch occured'amita.chouhan@hewitt.com' error=2 > Process proc; > proc = R...

send mail in Java
When i use the package of Notes Java API to compose a Java send mail application, i face a problem that it can't send any mails via outgoing mail (i.e. mail.box) on local PC. For details, please see below. Session s = NotesFactory.createSession(); Registration reg = s.createRegistration(); reg.switchToID(sender.id_file, sender.password); //using user's mail files on local Database db = s.getDatabase("",sender.usernsf); Document memo = db.createDocument(); memo.replaceItemValue("Form", "Memo"); ..... ..... //input mandatory data...

Send mail in Java
When i use the package of Notes Java API to compose a Java send mail application, i face a problem that it can't send any mails via outgoing mail (i.e. mail.box) on local PC. For details, please see below. Session s = NotesFactory.createSession(); Registration reg = s.createRegistration(); reg.switchToID(sender.id_file, sender.password); //using user's mail files on local Database db = s.getDatabase("",sender.usernsf); Document memo = db.createDocument(); memo.replaceItemValue("Form", "Memo"); ..... ..... //input mandatory data...

Sending mail with Java
I would like to know how to send a mail in a java application I searched on the web and I found some codes but it always don't work , because i don't have the name of a mail server i tried this : " props.put("mail.smtp.host", "smtp.gmail.com"); " but it doesn't work ... if any one could help me , i will be very gratefull Thanks Beckam <mesbaki87@gmail.com> wrote: >I would like to know how to send a mail in a java application >I searched on the web and I found some codes but it always don't >work , because i don't have the name ...

Please Help! java.mail trouble shooting for MMS sending over mm3
I need to send mail relaying with an smtp server that checks the headers section of the data field. The "TO" field should be the same as the "RCPT TO:" command, but without domain information. Code is just an example and it may not work. What i need is this: HELO ... MAIL FROM:<..> //here it is the recipient with domain name RCPT TO:<+391234567890@domain.com DATA MIME-Version: 1.0 Subject: #subject Date: Wed, 19 Nov 2003 16:42:53 +0100 From: #from //here it is the number without domain name. To: +1234567890 Content-Type: multipart/mixed; boundary="----_=...

To send email attachments with absolute path specified using JAVA mail API 1.4
Hi all, I need to send email attachments with their absolute paths specified in a DB table using Java Mail API 1.4 , i am newbie and not very much familiar in Java Mail methods ans functions, Thankz Jag "Jag" <arunjaganath@gmail.com> wrote in news:1167313870.947714.134240 @s34g2000cwa.googlegroups.com: > Hi all, > I need to send email attachments with their absolute paths > specified in a DB table using Java Mail API 1.4 , i am n...

Send mail script step
I have a file CLASSES with the classes of a school and a file STUDENTS with the students of the shool. The two files are related with the Class_ID field. I have a layout with the data from one record of the CLASS file and a portal showing all the students in that class. I want to use a script to sent e-mails to all the students in that class (assuming that there is a e-mail address field in students file). If I use the "Use all Recordn in found set" flag the mail is sent to all the studends of the school and not only to the students of that class. If I use "Use the current rec...

Java Application sending mail
Hello everybody, I am trying to send e-mail with a Java Application without any result. Does anyone can help me? BR Alessandro Sure, what's the problem? Opalinski opalpa@gmail.com http://www.geocities.com/opalpaweb/ "alexjcasol" <alexjcasol@tiscalinet.it> wrote in news:0b5a6f21f283abd55e7c13293f224351@localhost.talkaboutprogramming.com: > Hello everybody, > > I am trying to send e-mail with a Java Application without any result. > > Does anyone can help me? > > BR > Alessandro > > Now that's pretty vague. What have you trie...

i am getting error while sending mail using mail() function
i am getting following error. Warning: mail() [function.mail]: Failed to connect to mailserver at "smtp.gmail.com" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\LUGUBA\root\site\temp5.php on line 8 i have done the following (1) in php.ini file SMTP = smtp.gmail.com smtp_port = 465 sendmail_from = kathlal.panjabi@gmail.com (2) i am sendig mail using mail() function and i am passing only defaulst arguments to,subject,body is it enough to send a mail or something is missing?? and do not i need to give password of my ab...

can't send mail using mail()
hello, i am new to sending mail with php. the first function i tried is the mail(). when i passed the required parameters (to, message,subject), the apache error log said that the parameters are uninitialised. but the parameters already had value. do you know what is wrong? thank you fasisi wrote: > hello, > > i am new to sending mail with php. the first function i tried is the > mail(). when i passed the required parameters (to, message,subject), > the apache error log said that the parameters are uninitialised. but > the parameters already had value. > > do you ...

HELP: Agent to send mail on new mail arrived.
Notes/Domino 6.5.5 Windows 2003 Server Windows XP Client Can someone help me with writing and agent that will trigger when a new mail comes in to a regular maildatabase from "user@domain.com" and subject contains "this subject" From the mail body it should fetch the email adress to where to send. It is located after "mailto:". It also needs to fetch rows 15-18 into some sort of variable and get that presented in the body field. Subject needs to be "new subject". The body field needs to contain text that will have to be changed from ...

Mail will not send mail but will receive mail
At work I have a Wallstreet with Jaguar connected to a DSL line. Up until a couple days ago I have been able to use my personal ISP smtp address to send and receive mail. This is not the same company as the DSL provider. A couple days ago I was able to receive posts but not send them. I tried repairing permissions, and trashing the Mail prefs. Finally I emailed my ISP and the response was that I have to use the DSL carrier's smtp address. Yet, I've been using my personal ISP's smtp address for about a year. At home I use a dialup with the ISP and everything works fi...

Failed to send mail from Java Application
Hi, I need to send email from my java application into internet server(gmail or yahoo. etc). I tried with gmail smtp but they gives some time out. please send code related into that . by Joshan joshanjoe@gmail.com Checkout : http://www.javacommerce.com/destination65673/18274/SendMailUsingAuthentication.java That has all the code you need. Then you just need to be sure you have a SMTP server you can use. The server may require authentication, but that class includes how to use a username/pass. If you have problems, it may also be worth trying the IP of the server rather than its host name...

java send html mail problem
Hi, I have a web app. that runs on weblogic 8.1 sp4 on windows XP. Normally, it sends e-mails (text and html) with no trouble. However, I need to put a hyperlink in a mail message using below code snipped; Session session = (Session) ic.lookup("mySession"); MimeMessage msg = new MimeMessage(session); msg.setFrom(); msg.setHeader("X-Mailer", "sendhtml"); msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(email, false)); msg.setSentDate(new Date()); msg.setSubject(subject,"ISO-8859-9"); MimeBodyPart mbp = new MimeBodyPart(); ...

Web resources about - pls help me when i sent mail, it vil sending twice instead of once ,am using java.mail,am sending my code.... - comp.lang.java.programmer

Sending/receiving relationship - Wikipedia, the free encyclopedia
A sending/receiving relationship is one in which a public school district sends some or all of its students to attend the schools of another ...

U.K. Woman Faces 20 Months For Creating Fake Facebook Accounts, Sending Herself Abusive Messages
A woman in Cornwall in the U.K. came up with a creative way to use Facebook to accelerate a family spat, and it earned her 20 months in prison. ...

CHVRCHES - Dear guys, Please stop sending us emails like... - Facebook
Dear guys, Please stop sending us emails like this. This is one of the more polite ones. Other recent classics include "I'm going to give her ...

[...] Facebook Prevents Users From Sending Suspicious Friend Requests To Strangers, Inside Facebook [...] ...
Facebook has begun implementing new security measures to prevent friend request spamming. Some users are being shown a “This Request Can’t Be ...

A better experience for sending Tweets and DMs - Twitter Blog
... panel New Tweet panel in da...... Skip to main content Blog Got an account? Sign in Search form Search &nbsp A better experience for sending ...

How to Go From Working 60 Hours a Week to 40 By Sending 2 Emails a Week
I’m convinced 95% of cubicle workers who work over 60 hours a week constantly can cut it down to 40-45 hours by sending 2 emails a week to their ...

Emoticon and Emoji Box for iPhone -Save Emoticons,emoji,pic and images for Sending Message! 200 FREE ...
Get Emoticon and Emoji Box for iPhone -Save Emoticons,emoji,pic and images for Sending Message! 200 FREE emoticons and emojis - on the App Store. ...

Thanks for sending an iPhone4 and Sim T-Mobile but ... - Flickr - Photo Sharing!
... that's probably not going to work. (also, I'm sticking with the iPod touch).

Texas Man Makes $10K A Month Sending Potatoes With Personalized Messages In The Mail! - YouTube
Alex Craig, 24, said he came up with the idea for Potato Parcel earlier this year while having dinner with his girlfriend. His girlfriend called ...

'It was scary': widow speaks out as Muslim cleric pleads guilty to sending offensive letters to families ...
The young widow of fallen Australian soldier Brett Till still recalls the fear that came after she opened a letter sent to their home that labelled ...

Resources last updated: 2/4/2016 4:51:29 AM