public class MailUtil{
public static void main(String args[])
{
try{
String to = "kedu@xyz.com";
String from = "kedu@xyz.com";
// 1 - get a mail session
Properties props = new Properties();
props.put("mail.smtp.host", "Some Mail server");
props.put("mail.smtp.port", Integer.toString(2525));
props.put("mail.smtp.auth", true);
Session session = Session.getDefaultInstance(props);
// 2 - create a message
MimeMessage message = new MimeMessage(session);
message.setSubject("Test E-Mail through Java");
message.setText("This is a test of sending a " +
"plain text e-mail through Java.\n" +
"Here is line 2.\n"+ "Pl.reply\n"+ "Bye Bye");
// 3 - address the message
InternetAddress fromAddress = new InternetAddress(from);
InternetAddress toAddress = new InternetAddress(to);
message.setFrom(fromAddress);
message.setRecipient(Message.RecipientType.TO,toAddress);
// 4 - send the message
Transport.send(message);
}
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well
//System.out.println(mex);
mex.printStackTrace();
}
}
}
***********************************************************
But its showing me SendFailedException. WHY?
Pl.help me regarding same problem.
Thanks in advance..................
Joe carco
Ranch Hand
Joined: Apr 14, 2009
Posts: 82
posted
0
hi,
could you please in future post code using the "code" tags, it makes the code so much more readable.
The problem seems to be that youre enabling smtp authentication but you haven't provided any means to handle authentication: i.e. neither username nor password