Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Mail Send Failed error

 
Prakash Vaidyanathan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having the following code for sending mails from java.
import java.util.Properties;
import java.util.Date;
import javax.mail.Session;
import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetAddress;
import java.util.*;
import java.lang.*;
public class javamail{

public javamail(){

}
public void sendEmail (String userName, String passWord, String emailAddy)
{
String host = "208.220.253.27";
String to = emailAddy;
String from = "sap_rms@satyam.com";
String subject = "subjectMessage";
String messageText = "Some yadda, yadda";
boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(sessionDebug);
try
{
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new java.util.Date());
msg.setText(messageText);
Transport.send(msg);
} catch (Exception mex)
{
mex.printStackTrace();
}
}

public static void main(String args[])
{
javamail j = new javamail();
try{
j.sendEmail("p","p","chatwithvpat@yahoo.co.in");
}catch(Exception e)
{
System.out.println (e);
}

}
}

But when I am executing I am getting the following error:
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
class javax.mail.SendFailedException: 550 5.7.1 Unable to relay for chatwithvpat@yahoo.co.in
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at javamail.sendEmail(javamail.java:38)
at javamail.main(javamail.java:49)

Can anybody help me in this. What am i doing wrong in this?
Thanks in advance
Regards
Prakash
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic