File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes SendFailedException for sending simple email by using JavaMail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "SendFailedException for sending simple email by using JavaMail" Watch "SendFailedException for sending simple email by using JavaMail" New topic

SendFailedException for sending simple email by using JavaMail

kedu par

Joined: Nov 21, 2007
Posts: 11

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[])

String to = "";

String from = "";

// 1 - get a mail session
Properties props = new Properties();
props.put("", "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);
// 4 - send the message
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well

But its showing me SendFailedException. WHY? me regarding same problem.

Thanks in advance..................

Joe carco
Ranch Hand

Joined: Apr 14, 2009
Posts: 82

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

Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
You may want to peruse this extensive tutorial with many code examples. It explains authentication in detail, along with many other aspects of JavaMail.
I agree. Here's the link:
subject: SendFailedException for sending simple email by using JavaMail
It's not a secret anymore!