Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 28th, 2012  |  syntax: None  |  size: 1.51 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. javax.mail.MessagingException: Could not connect to SMTP host: mail.tranzlease.com, port: 465, response: -1
  2. public void sendtoGroup(String sub,String msg) {
  3.   try {
  4.     String host = "mail.myweb.com";
  5.     String from = "vinod.patil@myweb.com";
  6.     String pass = "12345";
  7.     Properties props = System.getProperties();
  8.     props.put("mail.smtp.starttls.enable", "false"); // added this line
  9.     props.put("mail.smtp.host", host);
  10.     props.put("mail.smtp.user", from);
  11.     props.put("mail.smtp.password", pass);
  12.     props.put("mail.smtp.port", "465");
  13.     props.put("mail.smtp.auth", "true");
  14.  
  15.     String[] to = {"vinod.patil@myweb.com","vinodpatil76@rediffmail.com"};
  16.     Session session = Session.getDefaultInstance(props, null);
  17.     MimeMessage message = new MimeMessage(session);
  18.     message.setFrom(new InternetAddress(from));
  19.  
  20.     InternetAddress[] toAddress = new InternetAddress[to.length];
  21.  
  22.     // To get the array of addresses
  23.     for( int i=0; i < to.length; i++ ) { // changed from a while loop
  24.         toAddress[i] = new InternetAddress(to[i]);
  25.     }
  26.     System.out.println(Message.RecipientType.TO);
  27.  
  28.     for( int i=0; i < toAddress.length; i++) {
  29.         message.addRecipient(Message.RecipientType.TO, toAddress[i]);
  30.     }
  31.     message.setSubject(sub);
  32.     message.setText(msg);
  33.     Transport transport = session.getTransport("smtp");
  34.     transport.connect(host, from, pass);
  35.     transport.sendMessage(message, message.getAllRecipients());
  36.     transport.close();
  37.   } catch(Exception e) {
  38.     e.printStackTrace();
  39.     }
  40.   }
  41. }