I tried to create a form to send mail using the JavaMail API. However I keep on getting the message saying that host cannot be found. I have imported the following:- import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.io.*; import java.util.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*;
To start the mail, I have performed the following:-
//Create the JavaMail session Properties properties = System.getProperties(); properties.put("mail.smtp.host", EmailServer); Session session = Session.getDefaultInstance(properties, null); //Construct the message MimeMessage message = new MimeMessage(session); //Set the from address Address fromAddress = new InternetAddress(EmailFrom); message.setFrom(fromAddress); //Parse and set the recipient address Address toAddresses = InternetAddress.parse(EmailTo); message.setRecipients(Message.RecipientType.TO, toAddresses); Address ccAddresses = InternetAddress.parse(EmailCC); message.setRecipients(Message.RecipientType.CC, ccAddresses); Address bccAddresses = InternetAddress.parse(EmailBCC); message.setRecipients(Message.RecipientType.BCC, bccAddresses); //Set the subject and text message.setSubject(EmailSubject); message.setText(EmailMessage); Transport.send(message); I have used my own ISP email server.
Hi! Well I guess you havent tried to connect to your mail server. To do that you will have to create a Store object of the following type... // Get a Store object Store store = session.getStore("[your Server .. imap or smtp ]"); store.connect(host, user, password);
I guess that should be the problem. All the best Regds Gautham Kasinath
"In the country of the blind, the one eyed man is the King"
Gautham Kasinath CV at : http://www.geocities.com/gkasinath
posted 19 years ago
Thanks Gautham. The problem was actually the server. I cannot specify another smtp server except for the one hosting the servlet. The smtp server does not allow relaying.
Alas, poor Yorick, he knew this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop