• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

SendFailedException for sending simple email by using JavaMail

Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 = "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);
// 4 - send the message
catch (MessagingException mex) {
// Prints all nested (chained) exceptions as well

But its showing me SendFailedException. WHY?

Pl.help me regarding same problem.

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

Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

Posts: 43016
  • 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.
yeah, but ... what would PIE do? Especially concerning this tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic