Solved

Sending Mail twice using JavaMail

Posted on 2011-03-01
5
1,103 Views
Last Modified: 2012-05-11
Experts,

I have this method that sends an email to the requester once its called. instead it sends two email. jst like it is called twice. i reviewed the code make sure i called the mthod once and call sendMsg once.


my code is below, could anyone tell me what could be cause of the problem ? ><

Thanks
Shamma
Config conf = new Config("uaeu_server_config.prop");
  String host= conf.get("mail_server"); //"195.229.162.3";
  int port =Integer.parseInt(conf.get("mail_port"));
  String[] recipients = to.split(",");
  InternetAddress[] addressTo = new javax.mail.internet.InternetAddress[recipients.length];
  for (int i = 0; i < recipients.length; i++){
	  System.out.println();
    addressTo[i] = new javax.mail.internet.InternetAddress(recipients[i]);}
  Collection toCollection = Arrays.asList(addressTo); 
  HtmlEmail htmlEmail = new HtmlEmail();
  htmlEmail.setHostName(host);
  htmlEmail.setTo(toCollection);
  htmlEmail.setFrom(from);
  htmlEmail.setSubject(subject);
  htmlEmail.setHtmlMsg(emailTemplate);

  // set the alternative message
  htmlEmail.setTextMsg("Your email client does not support HTML messages");

  // send the email
  htmlEmail.send();

Open in new window

0
Comment
Question by:Web_Admin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Accepted Solution

by:
ioanton earned 167 total points
ID: 35005499
>>>String[] recipients = to.split(",");

Can you post here the value of the variable "to"?
0
 
LVL 40

Assisted Solution

by:gurvinder372
gurvinder372 earned 167 total points
ID: 35005510
just to confirm, that it is not called twice, please put a log (System.out.println) before line 21, and let us know if that log is not printed twice

also print the recipient length on line 6, see if these are the same names
0
 
LVL 47

Assisted Solution

by:for_yan
for_yan earned 166 total points
ID: 35005523
Does it send two messages conssitently all the time, or only from time to time?

I'm asking because I'm using JavaMail extensively and although in absolute majority
of cases it works as expected, from time to time I experience cases of double emails.
So maybe it is some quirk in JavaMail itself. But I experience this behavior in fact very rarely. perhaps once
in several hundred emails.
If you see it consistently all the time than this is probably another issue.  
0
 

Author Comment

by:Web_Admin
ID: 35005778
ioanton : the value is one email address

gurvinder372: i already added the two line in the begning of the method and at the end. it is printed once.

for_yan: it is happening today, was working fine with me ><

----

I use apache common mail library http://commons.apache.org/email/userguide.html
when i remove this line "htmlEmail.send();", it sends the email one time ><
0
 

Author Comment

by:Web_Admin
ID: 35005817
ok guys thank you all for ur response , i found that i there is inculde file i added that call this method too :D

Thanks, points divided
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running JavaFX on JDeveloper 12C 1 112
How do I remove an object from a 3 61
glassfish admin console 1 47
wild fly 8 startup error 2 79
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question