0 Replies Latest reply: Feb 17, 2008 12:54 AM by 843844 RSS

    java MAIL A big ?? for an organisation!!

      HI folks,

      I have used java mail apis and developed an application to send mails[ from GMAIL account].I am successful in sending mail from my home [with a single PC] .But, when i test my application in a campus LAN [ IN my college ], my application fails miserably, telling exception is authorisation required.I understand GMAIL uses SSL and am also providing correct username and password, BCOZ am able to send mails from my pc in home.

      Can any body come with a solution wats going wrong .. and one more thing NO PROXY is BEING used in our campus LAN.Can u point out wat other parameters may be a barrier in sending gmail programatically in java through my campus LAN [eg: firewall settings, but am able to send gmail in my CAMPUS through a BROWSER]
      the code i use is as below:
      import java.security.Security;
      import java.util.Date;
      import java.util.Properties;
      import javax.mail.Authenticator;
      import javax.mail.Message;
      import javax.mail.MessagingException;
      import javax.mail.PasswordAuthentication;
      import javax.mail.Session;
      import javax.mail.Transport;
      import javax.mail.internet.AddressException;
      import javax.mail.internet.InternetAddress;
      import javax.mail.internet.MimeMessage;

      public class GmailSender {

      public static void main(String[] args) throws AddressException, MessagingException {

      Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
      final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
      // Get a Properties object
      Properties props = System.getProperties();

      props.setProperty("mail.smtp.host", "smtp.gmail.com");
      props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
      props.setProperty("mail.smtp.socketFactory.fallback", "false");
      props.setProperty("mail.smtp.port", "465");
      props.setProperty("mail.smtp.socketFactory.port", "465");
      props.put("mail.smtp.auth", "true");
      props.put("mail.debug", "true");
      props.put("mail.store.protocol", "pop3");
      props.put("mail.transport.protocol", "smtp");
      final String username = "USERNAME(WITHOUT @)";
      final String password = "PASSWORD";
      Session session = Session.getDefaultInstance(props,
      new Authenticator(){
      protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication(username, password);

      // -- Create a new message --
      Message msg = new MimeMessage(session);

      // -- Set the FROM and TO fields --
      msg.setFrom(new InternetAddress("XXX@gmail.com"));
      msg.setText("How are you");
      msg.setSentDate(new Date());
      System.out.println("Message sent.");