File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

SendFailedException for sending simple email by using JavaMail

kedu par
Greenhorn

Joined: Nov 21, 2007
Posts: 11
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

Joined: Apr 14, 2009
Posts: 82
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
Marshal

Joined: Mar 22, 2005
Posts: 39551
    
  27
You may want to peruse this extensive tutorial with many code examples. It explains authentication in detail, along with many other aspects of JavaMail.


Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SendFailedException for sending simple email by using JavaMail
 
Similar Threads
Help me to run my first JavaMail app
Confusion in JavaMail
using google to send email by JavaMail
how to send email from java program
Java Mail Authentication