Results 1 to 4 of 4
  1. #1
    Ed
    Ed is offline Senior Member
    Join Date
    Jun 2007
    Posts
    110
    Rep Power
    0

    Default org.apache.commons.mail.EmailException: Cannot find valid hostname

    I'm using the library email of jakarta to send email, but in the method setHostName("") I don't know what I have to put there, and it returns me this

    org.apache.commons.mail.EmailException: Cannot find valid hostname
    for mail session.
    Last edited by Ed; 06-12-2007 at 03:21 PM.

  2. #2
    Peter is offline Senior Member
    Join Date
    Jun 2007
    Posts
    119
    Rep Power
    0

    Default

    you have to put your host name
    I'll give you an example
    Java Code:
      SimpleEmail email = new SimpleEmail();
      email.setHostName("mail.myserver.com");
      email.addTo("jdoe@somewhere.org", "John Doe");
      email.setFrom("me@apache.org", "Me");
      email.setSubject("Test message");
      email.setMsg("This is a simple test of commons-email");
      email.send();

  3. #3
    Jack is offline Senior Member
    Join Date
    Jun 2007
    Posts
    130
    Rep Power
    0

    Default

    Go to this page: Commons Email - Examples

  4. #4
    Jhovarie is offline Banned
    Join Date
    Feb 2011
    Posts
    65
    Rep Power
    0

    Thumbs up

    hey i tried this code i get some errors.
    Java Code:
    import org.apache.commons.mail.*;
    
    public class Main{
        public static void main(String[]args) throws EmailException{
            Email email = new SimpleEmail();
            email.setHostName("smtp.gmail.com");
            email.setSmtpPort(587);
            email.setAuthenticator(new DefaultAuthenticator("user@gmail.com", "*******"));
            email.setTLS(true);
            email.setFrom("user@gmail.com");
            email.setSubject("TestMail");
            email.setMsg("This is a test mail ... :-)");
            email.addTo("reciever@live.com");
            email.send();
        }
    }
    Java Code:
    run:
    Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Message
    	at Main.main(Main.java:5)
    Caused by: java.lang.ClassNotFoundException: javax.mail.Message
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    	... 1 more
    Java Result: 1
    is there some thing missing in my library?
    i already add apache.commons.mail
    commons-email-1.2.jar

Similar Threads

  1. Retreiving of mail body using mail number
    By chandu.v09 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-13-2008, 03:25 PM
  2. IP to HostName
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-11-2007, 09:07 PM
  3. Commons Library Framework 0.8.0
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 10-02-2007, 05:13 PM
  4. Commons validator
    By aczuczor in forum Web Frameworks
    Replies: 0
    Last Post: 07-27-2007, 09:46 AM
  5. Sending a mail with the local mail program
    By thedude in forum Advanced Java
    Replies: 2
    Last Post: 07-23-2007, 01:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •