Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail is unable to send mail to other domains

 
Raghu Jamwal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
I'm using using javamail to send mail in my JSP application.The mail works within its own domain but if you send to other domains the email doesn't get sent.What could be the problem?
This the code:
<jsp:useBean id="mail" class="bean.mailbean" scope="page" />
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.mail.event.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Random" %>
<%@ page import="java.sql.*" %>
<%
String name=request.getParameter("name");
String loginname=request.getParameter("loginname");
String emailaddress=request.getParameter("emailaddress");

Random cl = new Random();
int aa=cl.nextInt();
String aas=Integer.toString(aa);
if(aas.startsWith("-"))
{

aas=aas.substring(1,4);

}
else
{
aas=aas.substring(1,4);

}
String password=loginname+aas;

String newline = System.getProperty("line.separator");
String mailto=""+emailaddress+"";
String mailfrom="someone@bharatnet.com";
String subject="Hello";
String from="Bharatnet.Com";
String to="Dear "+name+","+newline+"";
String mess="Your Login Name is :"+loginname+""+newline+
"Your password is :"+password+""+newline+newline+
"You are requested to change this password as soon as possible "+newline+
"in you own interest .";
String mailhost="192.168.1.75";
mail.setMailto(mailto);
mail.setMailfrom(mailfrom);
mail.setSubject(subject);
mail.setFrom(from);
mail.setTo(to);
mail.setMess(mess);
mail.setMailhost(mailhost);
boolean b=mail.sendMessage();
if(b)
{
//out.println("Your mail has been sent");
}
else
{
//out.println("Your mail is NOT sent");
}
// out.println(b);
 
gautham kasinath
Ranch Hand
Posts: 583
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Well are you behind a firewall??
Regds
Gautham Kasinath
 
Danny Mui
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also if your mail server isn't setup to relay for the IP address the machine is on it won't work either. This protects against spammers using your mail server.
 
Raghu Jamwal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I got around it using loopback i.e localhost IP 127.0.0.1.
I guess you're right about the relay part
Thanx
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!