apache james : mail server

510 views Asked by At

The following is my code. This executed successfully. But I didn't see any mail in my inbox Anybody please help.

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class SendMail {
      public static void main(String args[]) throws Exception {


        String fromAddress = "[email protected]";   
        String toAddress = "[email protected]";        
        Properties properties = new Properties();     
        properties.put("mail.smtp.host", "localhost");     
        properties.put("mail.smtp.port", "25");     
        properties.put("mail.transport.protocol", "smtp"); 


        try             
        {         
            properties.put("mail.smtp.starttls.enable", "true");

            Session session = Session.getDefaultInstance(properties, null);

            Message message = new MimeMessage(session);         
            message.setFrom(new InternetAddress(fromAddress));         
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toAddress));          
            message.setSubject("Email from our JAMEs");         
            message.setText("hiiiiii!!");         
            Transport.send(message);          
            System.out.println("Email sent");     
        }     
        catch (MessagingException e)     
        {        
            e.printStackTrace();     
        } 
        }
}
1

There are 1 answers

0
jrtapsell On

You'll need to either login and send over one of:

  • POP
  • IMAP
  • Gmail API

or you can use a domain you control, at the moment you are trying to send as gmail.com, and being ignored because it knows your IP is not allowed to send as gmail.com, because of SPF, which limits spam by setting who can send as which domains

SPF (Wikipedia)