Error while sending email through JSP

R

ruds

I'm trying to send email through JSP, here is my code:
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*,
javax.activation.*, javax.mail.util.*, java.util.Properties" %>

<%
String from_user="(e-mail address removed)"; // for e.g.

String toAddress = "(e-mail address removed)";

// out.println(from_user);
// out.println(toAddress);
Properties props = new Properties();
props.put("mail.smtp.host", "128.9.100.20");
Session ses = Session.getDefaultInstance(props, null);
/*if (debug)
ses.setDebug(true);*/

MimeMessage message = new MimeMessage(ses);

InternetAddress from = new InternetAddress(from_user);
message.setFrom(from);

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

String subject = "FIR Query";
message.setSubject(subject);
String text = request.getParameter("msg");
message.setText(text);
message.setContent(text, "text/html");

Transport.send(message);
%>
<html>
<p align="center">The Message has been sent.</p>
<p align="center"><a href="./login.jsp">Click here to send another!</
a></p>
</html>

I'm getting error as;
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to
relay for (e-mail address removed)

What could be the problem?
 
N

Nigel Wade

ruds said:
I'm trying to send email through JSP, here is my code:
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*,
javax.activation.*, javax.mail.util.*, java.util.Properties" %>

<%
String from_user="(e-mail address removed)"; // for e.g.

String toAddress = "(e-mail address removed)";

// out.println(from_user);
// out.println(toAddress);
Properties props = new Properties();
props.put("mail.smtp.host", "128.9.100.20");
Session ses = Session.getDefaultInstance(props, null);
/*if (debug)
ses.setDebug(true);*/

MimeMessage message = new MimeMessage(ses);

InternetAddress from = new InternetAddress(from_user);
message.setFrom(from);

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

String subject = "FIR Query";
message.setSubject(subject);
String text = request.getParameter("msg");
message.setText(text);
message.setContent(text, "text/html");

Transport.send(message);
%>
<html>
<p align="center">The Message has been sent.</p>
<p align="center"><a href="./login.jsp">Click here to send another!</
a></p>
</html>

I'm getting error as;
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to
relay for (e-mail address removed)

What could be the problem?


The mail server that you are connecting to (128.9.100.20) is refusing to relay
mail for the recipient address "(e-mail address removed)".
 
R

Roedy Green

The mail server that you are connecting to (128.9.100.20) is refusing to relay
mail for the recipient address "(e-mail address removed)".

usually a SMTP server will refuse to forward mail for just anyone,
only mail for people at that domain.

You may have to logon. see http://mindprod.com/products1.html#BULK
using an "Authenticator". See
http://mindprod.com/jgloss/authentication.html

It may only accept mail from certain IPs, e.g. ones serviced by the
ISP who owns the mail server.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,829
Messages
2,569,737
Members
45,522
Latest member
CCPAnne66

Latest Threads

Top