
Sir, I tried ur send mail example but it giveng follwing error "Could not connect to SMTP host: localhost, port: 25" ,tried sendind from my gmail ac to rediffmail ac
mailapi
<html>
<head>
<title>Mail API</title>
</head>
<body><table border="1" width="50%" cellpadding="0" cellspacing="0">
<tr>
<td width="100%">
<form method="POST" action="mail.jsp">
<table border="1" width="100%" cellpadding="0" cellspacing="0">
<h1>Mail API</h1>
<tr>
<td width="50%"><b>To:</b></td>
<td width="50%"><input type="text" name="to" size="30"></td>
</tr>
<tr>
<td width="50%"><b>From:</b></td>
<td width="50%"><input type="text" name="from" size="30"></td>
</tr>
<tr>
<td width="50%"><b>Subject:</b></td>
<td width="50%"><input type="text" name="subject" size="30"></td> </tr> <tr>
<td width="50%"><b>Description:</b></td>
<td width="50%"><textarea name="description" type="text" cols="40" rows="15" size=100> </textarea>
</td> </tr> <tr>
<td><p><input type="submit" value="Send Mail" name="sendMail"></td>
</tr>
</table>
</form> </td>
</tr>
</table>
</body>
</html>
mail.jsp
<html>
<head>
<title>Mail</title>
</head><body>
<%
try{ Session mailSession = Session.getInstance(System.getProperties());
Transport transport = new SMTPTransport(mailSession,new URLName("localhost"));
transport.connect("localhost",25,null,null);
MimeMessage m = new MimeMessage(mailSession);
m.setFrom(new InternetAddress(%><%request.getParameter("from")%><%));
Address[] toAddr = new InternetAddress[] {
new InternetAddress(%><%request.getParameter("to")%><%)
};
m.setRecipients(javax.mail.Message.RecipientType.TO, toAddr );
m.setSubject(%><%request.getParameter("subject")%><%);
m.setSentDate(new java.util.Date());
m.setContent(%><%request.getParameter("description")%><%, "text/plain");
transport.sendMessage(m,m.getAllRecipients());
transport.close();
out.println("Thanks for sending mail!");
}
catch(Exception e){
out.println(e.getMessage());
e.printStackTrace();
}
%>
</body>
</html>
Please help Thanks.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.