• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is java mail API is slow  RSS feed

 
Amit Rogye
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
i'm using java mail api for sending mails. but it seems it is very slow it takes almost 20 secs for sending one mail. is there any efficient way to send mails. i'm using following code(sample)
----------------------------------------
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
class Mail_Send
{
public static void main(String args[])
{
String[] toaddr = {"amitis@rediffmail.com","amitis@rediffmail.com","amitis@rediffmail.com","amitis@rediffmail.com"};
for(int i=0; i < toaddr.length;i++)
{
Properties propsSendMail;
String mailHost;
Session session;
mailHost="10.16.0.39";
// create some properties and get the default Session
propsSendMail = System.getProperties();
propsSendMail.put ( "mail.transport.protocol", "SMTP" );
propsSendMail.put ("mail.smtp.host", mailHost);
session = Session.getInstance(propsSendMail, null);
session.setDebug(false);

try
{
// create a mime message
MimeMessage mail = new MimeMessage(session);
mail.setFrom(new InternetAddress("amitis@rediffmail.com"));
InternetAddress[] address = {new InternetAddress(toaddr[i])};
mail.setRecipients(Message.RecipientType.TO, address);
mail.setSubject("Test!! but have fun");
mail.setText("test message !!!");
// set the Date: header
mail.setSentDate(new Date());
// send the message
Transport.send(mail);
System.out.println("mail sent for " + toaddr[i] + "--" + new java.util.Date());
}
catch (Exception mex)
{
mex.printStackTrace();
}
}
}
}
--------------------------
 
Chris Stewart
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you run it straight out of an IDE (JBuilder), yeah it's slow. Deploy a JSP to use JavaMail and you'll see how fast it really is.
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amit R, your name is in violation of the JavaRanch naming standard. Please check: http://www.javaranch.com/name.jsp and then change your display name.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!