Hi All,
I am trying to send a mail from my
Java Program.
The Code i used is:
import java.io.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class SendApp {
public static void send(
String smtpHost, int smtpPort,
String from, String to,
String subject, String content)
throws AddressException, MessagingException {
// Create a mail session
java.util.Properties props = new java.util.Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", ""+smtpPort);
Session session = Session.getDefaultInstance(props, null);
// Construct the message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setText(content);
// Send the message
Transport.send(msg);
}
public static void main(String[] args) throws Exception {
// Send a
test message
send("smtp.mail.yahoo.com", 25, "sivadinesh7@gmail.com", "sivadinesh7@yahoo.co.in",
"re: dinner", "How about at 7?");
}
}
I am getting the exception "UnknownHostException".
Can anybody tell me a valid SMTP host so that i can fix this problem.
Thanks in Advance!!!
dinesh.