IntelliJ Java IDE
The moose likes Other JSE/JEE APIs and the fly likes Is java mail API is slow Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "Is java mail API is slow" Watch "Is java mail API is slow" New topic
Author

Is java mail API is slow

Amit Rogye
Greenhorn

Joined: Sep 09, 2001
Posts: 5
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

Joined: Sep 29, 2001
Posts: 124
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

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
 
 
subject: Is java mail API is slow
 
Threads others viewed
Java Mail Authentication
how to send email from java program
Confusion in JavaMail
Can not send Email from localhost
javax.mail package
developer file tools