Hi when I try to send a simple java mail using the below code I get the following exception.
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import java.io.UnsupportedEncodingException;
public class MailExample
{
public static void main(String args[])
{
String host = "smtp.rediffmail.com";
String from = "abc@rediffmail.com";
String to = "abc@rediffmail.com";
try
{
// Get system properties
Properties props = System.getProperties();
// Setup mail server
Authenticator auth = new PopupAuthenticator();
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "" + 25);
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, auth);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from, "FromName"));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to, "ToName"));
message.setSubject("Hello JavaMail");
message.setText("Welcome to JavaMail");
Transport.send(message);
System.out.println("Mail Sent");
}
catch (MessagingException e)
{
e.printStackTrace();
}
catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}
}
static class PopupAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("abc@rediffmail.com",
"password");
}
}
}
DEBUG: setDebug: JavaMail version 1.3.3
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.rediffmail.com", port 25, isSSL false
220 webmail39.rediffmail.com ESMTP
DEBUG SMTP: connected to host "smtp.rediffmail.com", port: 25
EHLO srirampv
250-webmail39.rediffmail.com
250 8BITMIME
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<abc@rediffmail.com>
250 ok
RCPT TO:<abc@rediffmail.com>
421 Authorization failed: please authenticate by doing get message first
DEBUG SMTP: Valid Unsent Addresses
DEBUG SMTP: ToName <abc@rediffmail.com>
DEBUG SMTP: Sending failed because of invalid destination addresses
RSET
250 flushed
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class com.sun.mail.smtp.SMTPAddressFailedException: 421 Authorization failed: please authenticate by doing get message first
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1141)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:536)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at MailExample.main(MailExample.java:39)
QUIT
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class com.sun.mail.smtp.SMTPAddressFailedException: 421 Authorization failed: please authenticate by doing get message first
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1141)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:536)
at javax.mail.Transport.send0(Transport.java:151)
at javax.mail.Transport.send(Transport.java:80)
at MailExample.main(MailExample.java:39)
I have replaced my actual email address with abc@rediffmail.com .Please help.