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 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 "JavaMail" Watch "JavaMail" New topic


lekha phijo

Joined: Oct 09, 2003
Posts: 29
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
Properties props = new Properties();
props.put("", "xxxx");
Session s = Session.getInstance(props,null);

MimeMessage message = new MimeMessage(s);

InternetAddress from = new InternetAddress("");
InternetAddress to = new InternetAddress("");
message.addRecipient(Message.RecipientType.TO, to);

message.setSubject("Test from JavaMail.");
message.setText("Hello from JavaMail!");


1)I have put my smtp mail host
The error I get is

javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 5.7.1 Unable to relay for

please help
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
I'm not sure, but it looks like your email server is refusing to do just what it says it's not doing, "to relay for".

From the same machine that you're attempting to run this Java code, can you telnet to port 25 on the email server and send an email "by hand" from

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
most mailservers will refuse to send mail that's not sent from their own domains using addresses in that domain.

This is to prevent them from being used as spam relays as well as to prevent non-customers/employers using a company's services without paying (bandwidth theft).

Talk to your network admins about which mailserver you can use, there's probably one.

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

I'm going to move this to "Other Java APIs," where JavaMail questions go.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: JavaMail
jQuery in Action, 3rd edition