I am trying to send mail using JAVAMAIL API with GMAIL SMTP on port 465.
Now, I setup my outlook smtp.gmail.com with port 465 and I was able to send e-mail using outlook. So, I am sure it can be done using javamail as well. However, when I tried the same with javamail, I keep getting the following authentication error: Coud someone please let mne know how to get rid of this error and make my code work?I appreciate your help.
Thanks,
Venkat
Error:
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Su
n Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth false
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 465, isSSL false
220 mx.gmail.com ESMTP i20sm2352180wxd
DEBUG SMTP: connected to host "smtp.gmail.com", port: 465
EHLO vkat
250-mx.gmail.com at your service
250-SIZE 20971520
250-8BITMIME
250-AUTH LOGIN PLAIN
250 ENHANCEDSTATUSCODES
DEBUG SMTP: Found extension "SIZE", arg "20971520"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<vkat007@gmail.com>
530 5.7.0 Authentication Required i20sm2352180wxd com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Authentication Required i20sm2352180wxd
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1333)
//session = Session.getDefaultInstance(p);
MimeMessage msg = new MimeMessage(session);
msg.setText(text);
msg.setSubject(subject);
Address fromAddr = new InternetAddress("vkat007@gmail.com");
msg.setFrom(fromAddr);
Address toAddr = new InternetAddress(_to);
msg.addRecipient(Message.RecipientType.TO, toAddr);
System.out.println("Message: " msg.getContent());
Transport.send(msg);
}
catch (Exception mex) { // Prints all nested (chained) exceptions as well
System.out.println("I am here??? ");
mex.printStackTrace();
}
}
private class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("vkat007@gmail.com", "xxxxxxxxxxx"); // password not displayed here, but gave the right password in my actual code.
}
}
return new PasswordAuthentication("vkat007@gmail.com", "xxxxxxxxxxx");
instead to typing your complete email address try
typing your userid and password. then execute the code.
return new PasswordAuthentication("vkat007", "xxxxxxxxxxx");
You have the complete code. It's included with the
JavaMail download bundle. Use the instructions in the
FAQ to invoke the demo programs with the correct
parameters and it will work.