Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SendFailedException for sending simple email by using JavaMail

 
kedu par
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have program for sending simple email by using javamail as follows ->

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

this posting in suns java forum should solve your problem
http://forums.sun.com/thread.jspa?threadID=345884&start=0

cheers
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to peruse this extensive tutorial with many code examples. It explains authentication in detail, along with many other aspects of JavaMail.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic