| | |
Emaul in jsp
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2007
Posts: 3
Reputation:
Solved Threads: 0
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);
}
%>
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);
}
%>
•
•
Join Date: Jan 2008
Posts: 35
Reputation:
Solved Threads: 5
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/a...&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/javamai...tml#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
According to http://mail.google.com/support/bin/a...&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/javamai...tml#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
![]() |
Other Threads in the JSP Forum
- Previous Thread: conenction to databse pool
- Next Thread: Getting key value from property file in jSP
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial update video web





