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
posted
0
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
posted
0
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.