Advertisement

07.01.2008 at 05:02AM PDT, ID: 23529817 | Points: 500
[x]
Attachment Details

Problem when sending email using spring MVC framework . It sends 2  emails to each customer.It shoud send only one.

Asked by Shakil_Akhtar in J2EE Frameworks, JavaMail, Jakarta Struts

Hi Experts i am sending emails to selected customers using spring mvc framework. But when i am iterating for loop to send email it send 2 emails to each iterated customer.
I am putting  my controller and app-servlet.xml entries here to see my errors.
Please help me .

Thnx.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
// My controller where i am invoking email sending operation.
 
public class CustomerDetailsController extends MultiActionController {
    private MailSender mailSender;
   
    private SimpleMailMessage templateMessage;
 
SimpleMailMessage msg = getTemplateMessage();
        for (int i = 0; i < custDetailList.size(); i++) {
 
            CustomerDetailDTO custDetail = (CustomerDetailDTO) custDetailList
                    .get(i);
            String email1 = custDetail.getEmailFirst();
            String email2 = custDetail.getEmailSecond();
             String[] email = new String[2];
            if (!StringUtils.isBlank(email1)) {
                email[0] = email1;
            }
            if (!StringUtils.isBlank(email2)) {
                email[1] = email2;
            }
            if (!StringUtils.isBlank(email[0]) & !StringUtils.isBlank(email[1])) {
                msg.setTo(email);
            } else {
                msg.setTo(email[0]);
            }
            // setting subject of mail.
            
            msg.setSubject("Wire Confirmation");
            StringBuilder messageBody = new StringBuilder();
            messageBody.append("Please see confirmations below : \n\n");
            msg.setText(messageBody.toString());
 
            try {
                getMailSender().send(msg);
            } catch (MailException me) {
                logger.error("error in sending mail", me);
 
            }
}
}
 
    public MailSender getMailSender() {
        return mailSender;
    }
 
    
    public void setMailSender(MailSender _mailSender) {
        this.mailSender = _mailSender;
    }
 
    
    public SimpleMailMessage getTemplateMessage() {
        return templateMessage;
    }
 
  
    public void setTemplateMessage(SimpleMailMessage _templateMessage) {
        this.templateMessage = _templateMessage;
    }
}
 
// app-servlet.xml entries for this .
 
<bean id="customerDetailsController"
		class="com.fareis.afm.wire.controller.CustomerDetailsController">
		<property name="methodNameResolver">
			<ref bean="paramMethodNameResolver" />
		</property>
<property name="mailSender">
			<ref bean="mailSender" />
		</property>
		<property name="templateMessage">
			<ref bean="templateMessage" />
		</property>
</bean>
 
<bean id="mailSender"
		class="org.springframework.mail.javamail.JavaMailSenderImpl">
		<property name="host" value="myhost" />
	</bean>
 
	<!-- this is a template message that we can pre-load with default state -->
	<bean id="templateMessage"
		class="org.springframework.mail.SimpleMailMessage">
		<property name="from" value="shakil@domain.com" />
	<!-- 	<property name="subject" value="Your Request" /> -->
	</bean>
[+][-]07.01.2008 at 06:14AM PDT, ID: 21907443

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.21.2008 at 03:04AM PDT, ID: 22277681

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906