how to code a function to send an email to a predetermine email address.
I developt a sample but i got som error message due to mailhost .
the error is showen in attached file.
can anyone say me how to solve this problem. i tried several mailhost, but it was useless.

the code i wrote is :
<%@ page import="sun.net.smtp.SmtpClient, java.io.*" %>
<%
String from="myemail@hotmail.com";
String to="myemail@gmail.com";
try{
SmtpClient client = new SmtpClient("mail.gmail");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("To: " + to);
message.println("Subject: Sending email from JSP!");
message.println("This was sent from a JSP page!");
message.println();
message.println("Cool beans! :-)");
message.println();
message.println();
client.closeServer();
}
catch (IOException e){
System.out.println("ERROR SENDING EMAIL:"+e);
}
%>

Relaying issues are the most common problem when trying to send E-mail with a website. You need to make sure the SmtpClient settings are appropriate. From your code sample, you are trying to make use of gmail's mail server, in which case you need to use the appopriate server name, port, method, and credentials.

According to http://mail.google.com/support/bin/answer.py?hl=en&answer=13276:

server: 'smtp.gmail.com'
port: 465
scheme: ssl
username: your gmail username (i.e., whatever at gmail dot com)
password: your gmail password

However, according to the JavaMail FAQ (http://java.sun.com/products/javamail/FAQ.html#security):
"The JavaMail APIs currently have no support for sending or receiving secure email."

So you cannot send mail via g-mail's smtp server. You will need another smtp server, either a mail server that you use that would allow such (like the one you get your own E-mail from, besides g-mail, if you have another). If there are none, then you cannot send e-mail, unless you can install an smtp client on the server you are hosting this website and configure it to send your mail.

~ mellamokb

commented: Nice info +7
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.