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 = "testmail@gmail.com";
String toAddress = "testmail@gmail.com";
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();
}
}
}