java mail API

Ads
 

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
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 example  how to download javamail software give one examples   Please visit the following link: Java Mail API
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
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
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  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
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
mail
mail  how to send mail using jsp   Please visit the following links: JSP Send Mail Java Mail Tutorials
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
java api
java api  what is work of api in java   An application programming interface (API) is a library of functions that Java provides.... For more information,visit the following link: Java API
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: <
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
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
Java API
Java API what is Java API? API stands for Application Programming Interface..., interfaces with their methods, constructors that come with JDK. Java API included... has to use these code through Java API..In java most task are done by API
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
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
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.
java API
java API  Hi friends, please tell me that is it possible to communicate with hardware Through RS232 in java on windows platform?? Thanks in advance
java API for adobe
java API for adobe  where I can find adobe api for ReaderExtensionsServiceClient class ? plz help

Ads