0 Replies - 603 Views - Last Post: 03 July 2013 - 10:07 PM

#1 amit2011  Icon User is offline

  • D.I.C Head

Reputation: -13
  • View blog
  • Posts: 64
  • Joined: 17-March 11

Send email in jsp to outlook ids?

Posted 03 July 2013 - 10:07 PM

Hi, I want to create a form on my website through which user can send email to two-three OUTLOOK email-ids.

The form is just like user enters his/her email-id, name, subject, message and send mail to outlook ids.
The users id an be gmail, yahoo etc. What shld be the port number, host etc in this case.

I've included these librries: mail.jar, activation.jar
<%@ page import="java.io.*,java.util.*,javax.mail.*"%>
<%@ page import="javax.mail.internet.*,javax.activation.*"%>
<%@ page import="javax.servlet.http.*,javax.servlet.*" %>
<%
   
    String result;
   // Recipient's email ID needs to be mentioned.
   String to = "any outlook email id";

   // Sender's email ID needs to be mentioned
   String from = "rahulll2007@yahoo.co.in"; // or gmail id

   // Assuming you are sending email from localhost
  String host = "smtp.gmail.com";
   
 
  //
  //
   boolean sessionDebug = false;

   try{
   
   // Create some properties and get the default Session.
    Properties props = System.getProperties();

    props.put("mail.smtp.auth", "true");
    props.put("mail.smpt.host", host);
    props.put("mail.smtp.port", "25");
    props.put("mail.smtp.starttls.enable", "true");


    Session mailSession = Session.getDefaultInstance(props, null);
 
    // Set debug on the Session
     
   mailSession.setDebug(sessionDebug);
 
  // Instantiate a new MimeMessage and fill it with the 
  // required information.
  
      // Create a default MimeMessage object.
      MimeMessage message = new MimeMessage(mailSession);
      // Set From: header field of the header.
      message.setFrom(new InternetAddress(from));
      // Set To: header field of the header.
      message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
      // Set Subject: header field
      message.setSubject("This is the Subject Line!");
      // Now set the actual message
      message.setText("This is actual message");
      // Send message
      Transport.send(message);
      result = "Sent message successfully....";
   
   }
   catch (MessagingException mex) {
      mex.printStackTrace();
      result = "Error: unable to send EMAIL....";
   }
%>
<html>
<head>
<title>Send Email using JSP</title>
</head>
<body>
<center>
<h1>Send Email using JSP</h1>
</center>
<p align="center">
<% 
   out.println("Result: " + result + "\n");
%>
</p>
</body>
</html>



Is This A Good Question/Topic? 0
  • +

Page 1 of 1