• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JavaMail Exception.......HELP!!

 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ive written a class to send email from a website Im working on & am beating my head against the desk trying to figure out why i keep getting exceptions from my implementation of JavaMail. I originally tested this using my local machine & local isp which worked fine. I then contacted my sites hosting company about the default email server for my site. They told me it was just my domain name so i changed the smtp host to the domain name. Now I get an exception everytime i try to send email to anyone but the sites email address. I changed the file back to my local isp (still running from site) & it will only send email to my home address....I hope someone has a clue here. My tech support people are slower than death & this needs to be finished asap.
Here is the class for mail sending:
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class mailServ extends HttpServlet{
public void sendEmail (String userName, String passWord, String emailAddy) {
String host = "[myurl]";
String to = emailAddy;
String from = "[my default site email address]";
String subject = "Your Username and Password";
String messageText = "Welcome to Our site! \n\nYour username is: "+userName+" and your password is: "+passWord+" \n \nOnce you have logged into the site you may change your password to something easier to remember by going to the help link located at the top of every page of the site.";

boolean sessionDebug = false;
Properties props = System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(sessionDebug);
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate(new java.util.Date());
msg.setText(messageText);
Transport.send(msg);
}
catch (MessagingException mex){
mex.printStackTrace();
}
}
}
AND Here's the exception Im getting:
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550-Host thunder5.cwihosting.com [64.49.223.20] is not permitted
550-to relay through thunder5.cwihosting.com.
550-Perhaps you have not logged into the pop/imap server in the last 30 minutes.
550-You may also have been rejected because your ip address
550-does not have a reverse DNS entry.
550 relaying to <[email protected]> prohibited by administrator
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send(Transport.java:81)
at mailServ.sendEmail(mailServ.java:42)
at newUserSignUp.doPost(newUserSignUp.java:90)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:115)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:83)
at com.caucho.server.http.Invocation.service(Invocation.java:325)
at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:333)
at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:266)
at com.caucho.server.TcpConnection.run(TcpConnection.java:140)
at java.lang.Thread.run(Thread.java:484)
any & all help would be truely appreciated!! Thanks Much
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also faced the similar problem,
The smpt server provider has to give rights to user the for a particular port.
Transport transport = session.getTransport("smtp");
transport.connect(smtpserver," ", " ");
If it is provided corectley then all will work fine.
if you need i will give full coding.
to check the particular port is given permission, check sending mail to admin or faq person.
hope this will help u
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dalton
I think the problem lies in the code where you have written:
Session session = Session.getDefaultInstance(props, null);
I am not very good with javamail. I think you are passing a null value before getting an instance of the session object.
Correct use is:
Session getDefaultInstance(java.util.Properties props, Authenticator authenticator).
You are not authenticating yourself on the smtp server before getting the session instance. I think you should use a Authenticator object instead of null.
I think it'll help you.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set the properties properly.
set correct value for "mail.smtp.host" .u give u'r internet provider smtp server ip address the above property,then u can send mails to any domain.
cheers
Nagendra
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi DC Dalton,
I had the same problem and so after passing few minutes in the javadoc of JavaMail I'd found this :
Transport tr = agentSession.getTransport( "smtp" );
tr.connect( host, port, username, password );
try
{
message.saveChanges();
tr.sendMessage( message, message.getAllRecipients() );
}
finally
{
tr.close();
}
For me it's working so I hope it will help you.

Bye ThE_GuEsT
be nice... I like the terms of this site
 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, ensure that you have setup the following property in the Properties object that you pass into the constructor of the Session object:

prop.put("mail.smtp.auth", "true");

Marco
 
Hang a left on main. Then read this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic