Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending Emails using JSP

Status
Not open for further replies.

aarushi2001

Technical User
Nov 16, 2005
109
0
0
US
Hello,

Thanks to all.. I have learnt alot in JSP.. Final step is to send email using JSP.

My problem is if I put my own company email address in "to" field I am able to get emails, but if I enter gmail or any other email in "to" field, I get following error:

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Invalid Addresses;
nested exception is:
class com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for aarushi2001@gmail.com

org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
org.apache.jsp.test.mailer_jsp._jspService(org.apache.jsp.test.mailer_jsp:81)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.Exception: Invalid Addresses;
nested exception is:
class com.sun.mail.smtp.SMTPAddressFailedException: 550 5.7.1 Unable to relay for aarushi2001@gmail.com

MRI.MailerBean.sendMail(MailerBean.java:54)
org.apache.jsp.test.mailer_jsp._jspService(org.apache.jsp.test.mailer_jsp:65)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.12 logs.


This is my bean file:

package MRI;

import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.event.*;
import javax.mail.internet.*;

public final class MailerBean extends Object implements Serializable {

/* Bean Properties */
private String to = null;
private String from = null;
private String subject = null;
private String message = null;
public static Properties props = null;
public static Session session = null;

static {
/* Setting Properties for STMP host */
props = System.getProperties();
props.put("mail.smtp.host", "mail.mriint.com");
session = Session.getDefaultInstance(props, null);
}
/* Setter Methods */
public void setTo(String to) {
this.to = to;
}

public void setFrom(String from) {
this.from = from;
}

public void setSubject(String subject) {
this.subject = subject;
}

public void setMessage(String message) {
this.message = message;
}
/* Sends Email */
public void sendMail() throws Exception {
if(!this.everythingIsSet())
throw new Exception("Could not send email.");
try {
MimeMessage message = new MimeMessage(session);
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(this.to));
message.setFrom(new InternetAddress(this.from));
message.setSubject(this.subject);
message.setText(this.message);
Transport.send(message);
} catch (MessagingException e) {
throw new Exception(e.getMessage());
}
}

/* Checks whether all properties have been set or not */
private boolean everythingIsSet() {
if((this.to == null) || (this.from == null) ||
(this.subject == null) || (this.message == null))
return false;

if((this.to.indexOf("@") == -1) ||
(this.to.indexOf(".") == -1))
return false;

if((this.from.indexOf("@") == -1) ||
(this.from.indexOf(".") == -1))
return false;

return true;
}
}

This is compiling without no problems.

why am I getting this error?

Thanks
 
Your MTA is refusing to relay emails to any other domain apart from your own - it has nothing to do with Java.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
so my smtp is wrong? or my company inbox doesnt allow me to send messages outside?
 
The MTA that you are using (Mail Transfer Agent) - mail.mriint.com is refusing to relay mail to any address outside your domain - speak to your MTA admin.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top