SERVLETS - SENDING EMAIL



Similar documents
How to use JavaMail to send

UTL_SMTP and Sending Mail

Sun Microsystems, Inc JavaMail API Design Specification version 1.0b

Java Servlet and JSP Programming. Structure and Deployment China Jiliang University

Apache Tomcat 4.0 Sample Modified 06/09/04

1. Seam Mail Introduction 2. Configuration 3. Core Usage 4. Templating 5. Advanced Features

Java 7 Recipes. Freddy Guime. vk» (,\['«** g!p#« Carl Dea. Josh Juneau. John O'Conner

SSC - Web applications and development Introduction and Java Servlet (II)

Server Setup and Configuration

Web Application Architecture (based J2EE 1.4 Tutorial)

Hello World Portlet Rendered with JSP for WebSphere Portal Version 4.1

How To Test A Load Test On A Java Testnet 2.5 (For A Testnet) On A Test Server On A Microsoft Web Server On An Ipad Or Ipad (For An Ipa) On Your Computer Or Ipa

Installing the ASP.NET VETtrak APIs onto IIS 5 or 6

Sending Secure Electronic Mail (S/MIME) in Java (CAPS) the Easy Way May, 2009

Study of Development of Java Applications in Eclipse Environment and Development of Java Based Calendar Application with Notifications

2. Follow the installation directions and install the server on ccc

CS506 Web Design and Development Solved Online Quiz No. 01

Java and Web. WebWork

By Wick Gankanda Updated: August 8, 2012

API Document Webaroo Technology India Pvt. Ltd.

Supplement IV.E: Tutorial for Tomcat. For Introduction to Java Programming By Y. Daniel Liang

HP Asset Manager. Implementing Single Sign On for Asset Manager Web 5.x. Legal Notices Introduction Using AM

Implementing SQI via SOAP Web-Services

SharePoint Password Change & Expiration 3.0 User Guide

Web Container Components Servlet JSP Tag Libraries

Brekeke PBX Web Service

See the Developer s Getting Started Guide for an introduction to My Docs Online Secure File Delivery and how to use it programmatically.

JMETER - MONITOR TEST PLAN

James: The Java Apache Mail Enterprise Server

Table of Contents. Java CGI HOWTO

Web Applications. For live Java training, please see training courses at

SQLITE C/C++ TUTORIAL

INTRODUCTION TO WEB TECHNOLOGY

Install guide for Websphere 7.0

Hello World RESTful web service tutorial

E-invoice manual Instruction for a client implementation of the B2B web service

Introduction to HP ArcSight ESM Web Services APIs

Web Applications. Originals of Slides and Source Code for Examples:

NGASI AppServer Manager SaaS/ASP Hosting Automation for Cloud Computing Administrator and User Guide

Java Servlet 3.0. Rajiv Mordani Spec Lead

ServletExec TM 5.0 User Guide

Oracle Hyperion Financial Management Custom Pages Development Guide

Software Design Document Securing Web Service with Proxy

Using the DataDirect Connect for JDBC Drivers with WebLogic 8.1

Sending an Message from a Process

KINETIC SR (Survey and Request)

Volume 1: Core Technologies Marty Hall Larry Brown. An Overview of Servlet & JSP Technology

Intellicus Single Sign-on

etoken Enterprise For: SSL SSL with etoken

RPC over XML. Web services with Java. How to install it? Reference implementation. Setting the environment variables. Preparing the system

MarkLogic Server. Java Application Developer s Guide. MarkLogic 8 February, Copyright 2015 MarkLogic Corporation. All rights reserved.

CSI 2132 Lab 8. Outline. Web Programming JSP 23/03/2012

Configuring the SQL Server Data Source on WebSphere for LiveCycle Form Manager and LiveCycle Workflow

Web Application Programmer's Guide

Consuming, Providing & Publishing WS

Database Applications Recitation 10. Project 3: CMUQFlix CMUQ s Movies Recommendation System

Settings 1 September 2015

Using Internet or Windows Explorer to Upload Your Site

Web Development on the SOEN 6011 Server

DEPLOYING EMC DOCUMENTUM BUSINESS ACTIVITY MONITOR SERVER ON IBM WEBSPHERE APPLICATION SERVER CLUSTER

Crawl Proxy Installation and Configuration Guide

Using the DataDirect Connect for JDBC Drivers with the Sun Java System Application Server

SafeNet KMIP and Google Cloud Storage Integration Guide

SDK Code Examples Version 2.4.2

Overview of Web Services API

Spectrum Technology Platform

Google App Engine f r o r J av a a v a (G ( AE A / E J / )

Configuring IBM WebSphere Application Server 7.0 for Web Authentication with SAS 9.3 Web Applications

Kony MobileFabric. Sync Windows Installation Manual - WebSphere. On-Premises. Release 6.5. Document Relevance and Accuracy

CS346: Database Programming.

Application Notes for Packaging and Deploying Avaya Communications Process Manager Sample SDK Web Application on a JBoss Application Server Issue 1.

MIGS Payment Client Installation Guide. EGate User Manual

RHEV 2.2: REST API INSTALLATION

Installation Guide Apache Roller Weblogger Version 5.1 July 2014

How to Run Spark Application

IBM Unica emessage Version 8 Release 5 February 19, Transactional Administration Guide

Capture 8. Import Connector - Web Services SDK Developer s Guide Rev A

Merak Outlook Connector User Guide

An Overview of Servlet & JSP Technology

HYPERION SYSTEM 9 N-TIER INSTALLATION GUIDE MASTER DATA MANAGEMENT RELEASE 9.2

How To Install Storegrid Server On Linux On A Microsoft Ubuntu 7.5 (Amd64) Or Ubuntu (Amd86) (Amd77) (Orchestra) (For Ubuntu) (Permanent) (Powerpoint

How To Configure The Jasig Casa Single Sign On On A Workstation On Ahtml.Org On A Server On A Microsoft Server On An Ubuntu (Windows) On A Linux Computer On A Raspberry V

SafeNet KMIP and Amazon S3 Integration Guide

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Entrust Certificate Services. Java Code Signing. User Guide. Date of Issue: December Document issue: 2.0

FileMaker 11. ODBC and JDBC Guide

Using weblock s Servlet Filters for Application-Level Security

AdWhirl Open Source Server Setup Instructions

1 Introduction. 3 Open Mobile IS components 3.1 Embedded Database 3.2 Web server and Servlet API 3.3 Service API and template engine

Creating Java EE Applications and Servlets with IntelliJ IDEA

Customer Tips. Configuring Color Access on the WorkCentre 7328/7335/7345 using Windows Active Directory. for the user. Overview

Deploying Intellicus Portal on IBM WebSphere

DocuSign for SharePoint

Implementing a Web Service Client using Java

Getting Started with Web Applications

Transcription:

SERVLETS - SENDING EMAIL http://www.tutorialspoint.com/servlets/servlets-sending-email.htm Copyright tutorialspoint.com To send an email using your a Servlet is simple enough but to start with you should have JavaMail API and Java Activation Framework JAF installed on your machine. You can download latest version of JavaMail Version1.2 from Java's standard website. You can download latest version of JAF Version1.1.1 from Java's standard website. Download and unzip these files, in the newly created top level directories you will find a number of jar files for both the applications. You need to add mail.jar and activation.jar files in your CLASSPATH. Send a Simple Email: Here is an example to send a simple email from your machine. Here it is assumed that your localhost is connected to the internet and capable enough to send an email. Same time make sure all the jar files from Java Email API package and JAF package are available in CLASSPATH.

// Now set the actual message message.settext("this is actual message"); catch (MessagingException mex) Now let us compile above servlet and create following entries in web.xml... <servlet> <servlet-name>sendemail</servlet-name> <servlet-class>sendemail</servlet-class> </servlet> <servlet-mapping> <servlet-name>sendemail</servlet-name> <url-pattern>/sendemail</url-pattern> </servlet-mapping>... Now call this servlet using URL http://localhost:8080/sendemail which would send an email to given email ID abcd@gmail.com and would display following response: SEND EMAIL Sent message successfully... If you want to send an email to multiple recipients then following methods would be used to specify multiple email IDs: void addrecipients(message.recipienttype type, Address[] addresses) throws MessagingException Here is the description of the parameters: type: This would be set to TO, CC or BCC. Here CC represents Carbon Copy and BCC represents Black Carbon Copy. Example Message.RecipientType.TO addresses: This is the array of email ID. You would need to use InternetAddress method while specifying email IDs Send an HTML Email: Here is an example to send an HTML email from your machine. Here it is assumed that your

localhost is connected to the internet and capable enough to send an email. Same time make sure all the jar files from Java Email API package and JAF package ara available in CLASSPATH. This example is very similar to previous one, except here we are using setcontent method to set content whose second argument is "text/html" to specify that the HTML content is included in the message. Using this example, you can send as big as HTML content you like. // Send the actual HTML message, as big as you like message.setcontent("<h1>this is actual message</h1>", "text/html" );

catch (MessagingException mex) Compile and run above servlet to send HTML message on a given email ID. Send Attachment in Email: Here is an example to send an email with attachment from your machine. Here it is assumed that your localhost is connected to the internet and capable enough to send an email.

// Create the message part BodyPart messagebodypart = new MimeBodyPart(); // Fill the message messagebodypart.settext("this is message body"); // Create a multipar message Multipart multipart = new MimeMultipart(); // Set text message part multipart.addbodypart(messagebodypart); // Part two is attachment messagebodypart = new MimeBodyPart(); String filename = "file.txt"; DataSource source = new FileDataSource(filename); messagebodypart.setdatahandler(new DataHandler(source)); messagebodypart.setfilename(filename); multipart.addbodypart(messagebodypart); // Send the complete message parts message.setcontent(multipart ); catch (MessagingException mex) Compile and run above servlet to send a file as an attachement along with a message on a given email ID. User Authentication Part: If it is required to provide user ID and Password to the email server for authentication purpose then you can set these properties as follows: props.setproperty("mail.user", "myuser"); props.setproperty("mail.password", "mypwd"); Rest of the email sending mechanism would remain as explained above. Loading [MathJax]/jax/output/HTML-CSS/jax.js