Hi All,
I am getting the following error while executing the mail program in
java.
Exception in
thread "main" javax.mail.MessagingException: Unknown SMTP host: smtp;
nested exception is:
java.net.UnknownHostException: smtp
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1704)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:525)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at lang.SimpleMail.main(SimpleMail.java:38)
Caused by: java.net.UnknownHostException: smtp
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:284)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1672)
... 4 more
My Code snippet as follows:
Properties props = new Properties();
String username = "user";
String password = "password";
String host = "smtp";
String server = "mail.server.com";
props.setProperty("mail.transport.protocol", host);
props.setProperty("mail.host", server);
props.setProperty("mail.user", username);
props.setProperty("mail.password", password);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.", "true");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.socketFactory.fallback", "false");
Session mailSession = Session.getDefaultInstance(props,null);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("Testing JAVAMAIL PLAIN");
message.setContent("This is a test","text/plain");
message.addRecipient(Message.RecipientType.TO, new InternetAddress("email@server.com"));
transport.connect(host, username, password);
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();
Kindly help me to come out of this problem.
Thanks in advance.