Error Occurred while sending mail through gmail account

Hello,

I am writing 1 demo appln which will send a mail from my gmail account. It will show error like"javax.mail.MessagingException: 530 5.5.1 Authentication Required f77sm3109311pyh"

Here is Code : -

package demo;

import java.util.Properties;

import javax.mail.Address;

import javax.mail.Authenticator;

import javax.mail.Message;

import javax.mail.Session;

import javax.mail.Transport;

import javax.mail.internet.InternetAddress;

import javax.mail.internet.MimeMessage;

public class Demo {

/**

* @param args

*/

public static void main(String[] args) {

try

{

Properties properties=System.getProperties();

properties.put("mail.smtp.host","smtp.gmail.com");

properties.put("mail.smtp.auth","true");

properties.put("mail.from","sushrandive@gmail.com");

properties.put("mail.smtp.port","465");

properties.put("mail.smtp.starttls.enable","true");

properties.put("mail.smtp.socketFactory.port", "465");

properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

properties.put("mail.smtp.socketFactory.fallback", "false");

Authenticator auth = new PopupAuthenticator();

Session session = Session.getDefaultInstance(properties,auth);

session.setDebug(true);

// Define message

MimeMessage message = new MimeMessage(session);

message.addRecipient(Message.RecipientType.TO, new InternetAddress("sush_randive@yahoo.com"));

message.setSubject("Hello JavaMail");

message.setText("Welcome to JavaMail");

message.saveChanges();

Address address[] = message.getAllRecipients();

Address a1 = address[0];

System.out.println("Recipient : "+a1.toString());

Transport.send(message, message.getAllRecipients());

}

catch(Exception e){e.printStackTrace();}

}

}

and code for PopupAuthenticator :-

package demo;

import javax.mail.Authenticator;

import javax.mail.PasswordAuthentication;

import javax.swing.*;

import java.util.StringTokenizer;

public class PopupAuthenticator extends Authenticator

{

public PopupAuthenticator()

{

System.out.println("In Auth");

}

public PasswordAuthentication getPasswordAuthentication()

{

String username, password;

String result = JOptionPane.showInputDialog("Enter 'username,password'");

StringTokenizer st = new StringTokenizer(result, ",");

username = st.nextToken();

password = st.nextToken();

return new PasswordAuthentication(username, password);

}

}

But when i run this code i never get popup window asking for username/password and it throws follwing exception

javax.mail.SendFailedException: Sending failed;

nested exception is:

javax.mail.MessagingException: 530 5.5.1 Authentication Required f77sm3109311pyh

at javax.mail.Transport.send0(Transport.java:204)

at javax.mail.Transport.send(Transport.java:88)

at demo.Demo.main(Demo.java:66)

may i know wats wrong wid my code? I am confussed about when getPasswordAuthentication () method will call?

please reply me at sushrandive@gmail.com

thnx in advance ..

-Sushrut

[3353 byte] By [Sushruta] at [2007-11-26 20:07:02]
# 1
Unless you really want the popup, there's an easier way described here: http://java.sun.com/products/javamail/FAQ.html#smtpauthIf you want the popup and it's still not working, turn on session debuggingand post the debug output.
bshannona at 2007-7-9 23:08:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Hi bshannon ,

Thnx ..

I have removed the popup code from my PopUpAuthanticer.java file

But i got similar error ....

Here is Debug message : -

In Auth

Recipient : sush_randive@yahoo.com

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]

DEBUG: SMTPTransport trying to connect to host "smtp.gmail.com", port 465

DEBUG SMTP RCVD: 220 mx.google.com ESMTP y78sm4251719pyg

DEBUG SMTP SENT: helo sushrutr

DEBUG SMTP RCVD: 250 mx.google.com at your service

DEBUG: SMTPTransport connected to host "smtp.gmail.com", port: 465

DEBUG SMTP SENT: mail from: <sushrandive@gmail.com>

DEBUG SMTP RCVD: 530 5.5.1 Authentication Required y78sm4251719pyg

DEBUG SMTP SENT: quit

javax.mail.SendFailedException: Sending failed;

nested exception is:

javax.mail.MessagingException: 530 5.5.1 Authentication Required y78sm4251719pyg

at javax.mail.Transport.send0(Transport.java:204)

at javax.mail.Transport.send(Transport.java:88)

at demo.Demo.main(Demo.java:53)

can u please tell me when getPasswordAuthentication() will call ? and who is going to call this ...

Thnx in advance ...

Sushruta at 2007-7-9 23:08:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
Looks like you must be using a very very very old version of JavaMail.Have you tried downloading the latest version?
bshannona at 2007-7-9 23:08:57 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...