I am trying to learn JavaMail API.i am working on this.i have search much from google..i know for hosting mails, mail server is require and Apache james is a open source server.i have downloaded that.but i am not able to configure that.i dont understand how actualy javamail work with James.I am stucked.i am not understanding anything how to host mails using javamail and James..
Thank u in advance.any help wil be apreciated..

Recommended Answers

All 3 Replies

Did you read all the doocumentation for those 2 products? javaMail needs a mailserver, and the installation instructions can be found in the readme.txt that comes with the download. you'll also need to install some additional stuff (according to the manual).

Oracle provides a samplle code at http://javamail.kenai.com/nonav/javadocs/ .
i assume (from a quick look) that "my-mail-server" should be the IP of the computer you installed james on.

the james readme also details how you can setup your settings, using a configuration file, or a remote host.

sir,
i have read the documentation.i have installed javamail properly.but finiding problem in james.
i have gone through the link you provided,for host-i tried u use my ip address and even hosting using gmail by "pop.gmail.com" but me getting an error "MessagingException".

I am not able to understand how to use James for hosting email through JavaMail

read the documentation.i have installed javamail properly.but finiding problem in james.
i have gone through the link you provided,for host-i tried u use my ip address and even hosting using gmail by "pop.gmail.com

Well I have used JavaMail before for a personal program I created, here is the method for sending the mail(using gmail).

learn JavaMail API.i am working on this.i have search much from google..i know for hosting mails, mail server is require and Apache james is a open

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;



    public void javaMail(){

        final String username = "YourUsername@gmail.com";
        final String password = "password";

        Properties props = new Properties(); //Put properties here
        props.put("mail.smtp.auth", "true");// authorize 
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");

        //Start the session
        Session session = Session.getInstance(props,
          new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
          });

        try {



                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress("SetFromEmail"));//From
                message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("toSender@gmail.com"));//To
                message.setSubject("Comuptor Problem");
                message.setText("Dear USer"
                    + "Look a email!");

                Transport.send(message);

                System.out.println("Done");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.