Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relay Access Denied....(HELP..!!!!!)

 
Jignesh Kakkad
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import java.io.*;

public class T
{

public static void main(String[] args)
{

Properties props = new Properties();
props.put("mail.smtp.host", "mail.cloud9.net");
//props.put("mail.host", "SMTP.mail.yahoo.com");
//props.put("mail.host", "smtp.blabla.co.om");
try
{

Session mailConnection = Session.getInstance(props, null);

Address bill = new InternetAddress("jig2nesh@yahoo.com",true);
Address elliotte = new InternetAddress("jig2nesh@yahoo.com",true);
System.out.println(elliotte);
Message msg = new MimeMessage(mailConnection);

msg.setFrom(bill);
msg.setRecipient(Message.RecipientType.BCC, elliotte);
msg.setSubject("You must comply.");
msg.setContent("Resistance is futile. You will be assimilated!",
"text/plain");

Transport.send(msg);

}

catch(AddressException a)
{
}
catch (SendFailedException e)
{
//e.printStackTrace();
//System.out.println((e.getInvalidAddresses()).length);
System.out.println(e);
}
catch (MessagingException e)
{
}

}

}

we get invalid address and relay Access Denied Exception....
Please Help Us...

Jignesh
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few points (sorry to be critical): Why are you explicitly using strict validation of email addresses when new InternetAddress(java.lang.String address) does this by default? And empty catch blocks will always give you headaches.

Aside from that, both:

are perfectly valid RFC822 email addresses, so neither of these lines should be giving you an AddressException (are you sure that's what you are getting?)

"Access Denied" exceptions will be something to do with the connection to the SMTP server. Does "mail.cloud9.net" need any authentication/authorization? Are you behind a proxy or firewall?

Here's a list of things I always tell people to do when they have problems with JavaMail:
  • Enable SMTP debugging, so you can see the actual SMTP traffic.
  • Speak to the SMTP server admin and try to telnet to the server. Both are very quick ways to test whether you actually can access it in the way you want to. Any glitches/restrictions can be ironed out here before you have written a line of Java.
  • Write Transport and Connection Handlers which log activity properly (good to help you debug problems, and essential if you want the application to be supported by someone else)
  • Read the JavaMail FAQ's (if you haven't already - this will alert you to common issues people encounter. People are forever misunderstanding the implications of having a proxy server involved in the process for instance.
  • Develop and test you JavaMail code seperate from your SMTP server. Use Dumbster (or James if you must) to check your code is doing what you want it to, and generating the proper SMTP messages. That way you are not mixing debuging code with debugging infrastructure which makes the process easier in the long run.

  •  
    Jignesh Kakkad
    Ranch Hand
    Posts: 49
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanx For replying me
    Yes i know what i am getting this is true..
    I am getting exception like invalid address and relay access denied..!!!

    And do u what are other free SMTP service provider..?

    Thanx
    Jignesh Kakkad
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic