posted 23 years ago
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.