Solved

Sending Mail twice using JavaMail

Posted on 2011-03-01
5
1,033 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

743 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now