• 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

SendFailedException for sending simple email by using JavaMail

 
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..................







 
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
 
Rancher
Posts: 43016
76
  • 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
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic