java mail API

java mail API

<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>
  </p>
  </form>
  </td>
  </tr>
</table>
</body>
</html>

 Here the code of JSP:  mail.jsp

<%@ page language="java" import="javax.naming.*,java.io.*,javax.mail.*,
javax.mail.internet.*,com.sun.mail.smtp.*"%>
<html>
<head>
<title>Mail</title>
</head>
<body>
<%
try{
  Session mailSession = Session.getInstance(System.getProperties());
  Transport transport = new SMTPTransport(mailSession,new URLName("www.gmail.com"));
  transport.connect("smtp.gmail.com",465,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>
View Answers

March 28, 2012 at 10:39 PM

This code shows an error 'could'n connect to smtp host' can you help me in this

Ads









Related Tutorials/Questions & Answers:
Java Mail API Tutorial
Java Mail API Tutorial  I have to write programs using the Java Mail API. I want to learn the Java Mail API. Let's know the urls to learn Java Mail... Mail API. The Java Mail API allows you to send, read emails from Java program
java mail API
java mail API  <html> <head> <title>Mail API<...%" cellpadding="0" cellspacing="0"> <h1>Mail API</h1> <tr>...="submit" value="Send Mail" name="sendMail"></td> </tr> <
Advertisements
Introduction to Java Mail API
Introduction to Java Mail API       The Java Mail API allows the developers to add mailing... with the Java Mail API. The Java Mail API provides a platform-independent framework
Digitally signing email through Java mail api
Digitally signing email through Java mail api  how to sign (Digital Signature) one message using Java mail api
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user... the emails from the James mail server irrespective of the users
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user... the emails from the James mail server irrespective of the users
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user... the emails from the James mail server irrespective of the users
Read Email using Java Mail API - James
Read Email using Java Mail API - James   https://www.roseindia.net/javamail/send-mail.shtml From this sample, i understand that we need to pass user... the emails from the James mail server irrespective of the users
java mail
java mail example  how to download javamail software give one examples   Please visit the following link: Java Mail API
Technical description of Java Mail API
Technical description of Java Mail API   ... Mail API. You must understand the Java Mail API before actually delving... Mail API Lets understand the core Java Mail API classes. Session Session
java mail
java mail  how to download javamail software give one examples   Please visit the following link: Java Mail API
How to set attachment from browse button to send mails using java mail api
How to set attachment from browse button to send mails using java mail api   Hello Sir, I am making Email Sending app using java mail api in jsp and servlet in that i have to make attachment option available using
java mail
java mail  this code showing an error couldn't connect smtp host please help <%@ page language="java" import="javax.naming.*,java.io....(); out.println("Thanks for sending mail!"); } catch(Exception e
mail
mail  I wrote a program to send mail using smtp. But there is an error message " could not connect to smtp.gmail.com port 465. what is the problem how can i solve it ...   Please visit the following link: Java Mail API
ModuleNotFoundError: No module named 'Royal-Mail-Rest-API'
ModuleNotFoundError: No module named 'Royal-Mail-Rest-API'  Hi, My... named 'Royal-Mail-Rest-API' How to remove the ModuleNotFoundError: No module named 'Royal-Mail-Rest-API' error? Thanks   Hi
mail
mail  how to send mail using jsp   Please visit the following links: JSP Send Mail Java Mail Tutorials
java mail programs
java mail programs  I got some codes from this about sending mail,forwarding mail,multipart mail etc..and I compiled and executed it,but it did... output.actually,do I need a mail server to get correct output of these codes?plz help me, I
send mail using smtp in java
send mail using smtp in java  How to send mail using smtp in java?   Sending mail in JSP - SMTP
java mail sending with images
java mail sending with images  I need to send images through java mail without giving content path(i.e. we don't want hard code the image path)can you tell me the idea?   Please visit the following links: http
java mail send using setText()
java mail send using setText()  Hai , Am newly mail send portion in java , Here i write my code , final String userName = "[email protected] in java file . but if i use set Content() method, mail content is display html
Sending images through java mail
Sending images through java mail  Am trying to develop greeting... and by clicking one image the control go to mail sending page in that the image should add to body part and the mail will sent to recipients..... please give me any idea
Send multipart mail using java mail
Send multipart mail using java mail       This Example shows you how to send multipart mail using java mail. Multipart is like a container that holds one or more body
Handle EML(Electronic mail) file with Java Mail
Handle EML(Electronic mail) file with Java Mail       This Example shows you how to read any eml(Electronic mail) file using javamail api. eml is a simple email, all eml
Read attachment message using Java Mail
a Attachment message using javamail api. Java Mail API provides classes to send multiple... Read attachment message using Java Mail   ...;mail Return-Path: <[email protected]> Delivered-To: <
java source code to create mail server using struts2
java source code to create mail server using struts2  java source code to create mail server using struts2
How i can send testing mail on my id using java?
How i can send testing mail on my id using java?  Which packages i should use to implementing java mail service??? Thanks
how to get mail exchange records using java dns protocol
how to get mail exchange records using java dns protocol  Hi, how to get DNS mail exchage records(MX) using struts2 framework(server:glassfishv3) Thanks, B.Sucharitha.
Forwarding Messages using Java Mail
Forwarding Messages using Java Mail   ... using javamail api. there is no method to forward a mail from one user to another... and get message content then send its for another user. Java code given below
Apache Mail server (James)
and a mail application platform. Latest version is James 2.3.1. Mailet API The Apache Mailet API is a Java API that comes with the James mail server... Apache Mail server (James)      
How to show all header information of message using Java Mail api
How to show all header information of message using Java Mail api       This Example shows you how to show all header of any message using javamail api. All messages
Maven dependency for com.aerse - mail version 1.0 is released. Learn to use mail version 1.0 in Maven based Java projects
Maven dependency for  com.aerse  - Version 1.0 of mail released The developers of   com.aerse - mail project have released the latest... - mail library is 1.0. Developer can use this version ( com.aerse - mail version

Ads