[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Sending Mail twice using JavaMail

Posted on 2011-03-01
5
Medium Priority
?
1,167 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
5 Comments
 
LVL 9

Accepted Solution

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

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

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 668 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 664 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 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