Solved

Sending Mail twice using JavaMail

Posted on 2011-03-01
5
1,089 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 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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
xampp tool 12 56
fibonacci ten numbers 4 46
servlet example 17 53
SequenceInputStream example 3 19
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

808 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