Search code examples
javamail-server

about mock-javamail


I need an mail server in java that can handle incoming and outgoing mails (POP3- IMAP- SMTP protocols).

I thought about trying to use mock-javamail.

I downloaded the:

svn co https://svn.java.net/svn/mock-javamail~svn

I want to import the project in eclipse and start configure it and test it.

I didn't find any informations about how to build this project in order to open it in eclipse. I don't know anything about the license. Can someone please help?

I already have the smtp-pop3-imap clients done using JavaMail api.

Now I need to implement a mail server in java that can handle incoming - outgoing emails.


Solution

  • Here is a simple way you can test the mail api.

    import org.apache.commons.mail.Email;
    import org.apache.commons.mail.EmailException;
    import org.apache.commons.mail.SimpleEmail;
    
    public class MyMailSender {
    
        public void sendMail(String to, String from, String subject, String msg) throws EmailException {
           Email email = new SimpleEmail();
           email.addTo(to);
           email.setFrom(from);
           email.setSubject(subject);   
           email.setMsg(msg);
           email.setHostName("testmail.com");   
           email.send();  
        }
    
    }