JavaMail JavaMail Classes Sending a Message Using JavaMail (MessageSend.java) Sending a Message to Multiple Recipients (SendToMany.java) Installing JavaMail.

Slides:



Advertisements
Similar presentations
Basic Communication on the Internet:
Advertisements

AO- 2 (part 2 of 2) Pass + Send. Receive. Reply. Forward. With more than 1 attachment.
Ivan Maurits. Untuk mengirim menggunakan java anda harus memiliki JavaMail API dan Java Activation Framework (JAF) yang telah terinstall dalam komputer.
Topic : JavaMail API (1) Sending and Receiving s Kaster Nurmukan.
Lesson 7: Business, , & Personal Information Management
JavaMail Electronic Mail Concepts JavaMail Classes Examples of Sending JavaMail JavaBeans Activation Framework Multi-part Messages Example of Sending Attachments.
Writing Simple Clients in Java Using Sockets using the JavaMail API.
J2EE JavaMail API Presented by Bartosz Sakowicz. Instalation Java Mail API: Java Activation Framework.
CS 580 Client-Server Programming Spring Semester, 2006 Doc 20 Sending Apr 13, 2006 Copyright ©, All rights reserved SDSU & Roger Whitney, 5500.
Remote mailbox access gateway Software lab project.
Chapter 2: Application layer  2.1 Web and HTTP  2.2 FTP 2-1 Lecture 5 Application Layer.
Exploring Microsoft Office Outlook Microsoft Outlook 2000 A Desktop Information Manager By Robert T. Grauer Maryann Barber.
Technion – Israel Institute of Technology Department of Electrical Engineering Software Lab Remote Mailbox based on.NET technology Michael and Eugene Shamis.
Chapter 30 Electronic Mail Representation & Transfer
CSCI 6962: Server-side Design and Programming Server Created .
POP Configuration Microsoft Outlook Express 6.x.
Architecture of SMTP, POP, IMAP, MIME.
1 JavaMail (1) Presented by: Ke Duan Instructor: Dr. V. “Juggy” Jagannathan.
JAVA MAIL API. High level representation of the basic components of any mail system. The components are represented by abstract classes in the javax.mail.
Sending and Receiving s
POP Configuration Microsoft Outlook What is POP? Short for Post Office Protocol, a protocol used to retrieve from a mail server. Most.
» Explain the way that electronic mail ( ) works » Configure an client » Identify message components » Create and send messages.
1 What is Electronic Mail Exchanging information via computer networks Electronic mail addresses SMTP (Simple Mail Transfer Protocol) Client/Server based.
Computer Concepts 2014 Chapter 7 The Web and .
1 Application Layer Lecture 5 Imran Ahmed University of Management & Technology.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 9
Lecturer: Maxim Podlesny Sep CSE 473 File Transfer and Electronic in Internet.
© 2010 Computer Science Faculty, Kabul University ELECTRONICE MAIL CONTINUED… 6 TH LECTURE 9, May, 2010 Baseer Ahmad Baheer.
Computer Networking From LANs to WANs: Hardware, Software, and Security Chapter 12 Electronic Mail.
Electronic Mail Originally –Memo sent from one user to another Now –Memo sent to one or more mailboxes Mailbox –Destination point for messages.
A form of communication in which electronic messages are created and transferred between two or more devices connected to a network.
 TCP/IP is the communication protocol for the Internet  TCP/IP defines how electronic devices should be connected to the Internet, and how data should.
Computer Networks26-1 Chapter 26. Remote Logging, Electronic Mail and File Transfer.
CPT 499 Internet Skills for Educators Electronic Mail Session Five.
Simple Mail Transfer Protocol (SMTP)
Sending Topic 4, Chapters 9, 10 Network Programming Kansas State University at Salina.
1 Using Messages sent from machine to machine and stored for later reading. You will use a client to read –Type mail or pine in UNIX to read.
The Internet 8th Edition Tutorial 2 Basic Communication on the Internet: .
Electronic Mail. Client Software and Mail Hosts –Client PC has client software that communicates with user’s mail host –Mail hosts deliver.
What is and How Does it Work?  Electronic mail ( ) is the most popular use of the Internet. It is a fast and inexpensive way of sending messages.
File Transfer Protocol (FTP)
IBM TSpaces Lab 1 Introduction. Summary TSpaces Overview Basic Definitions Basic primitive operations Reading/writing tuples in tuplespace HelloWorld.
Topic : JavaMail API Kaster Nurmukan. Overview of JavaMail API Javax.mail.Session Javax.mail.Authenticator and PasswordAuthentication Javax.mail.Message.
Concepts  messages are passed through the internet by using a protocol called simple mail transfer protocol.  The incoming messages are.
CS 3830 Day 9 Introduction 1-1. Announcements r Quiz #2 this Friday r Demo prog1 and prog2 together starting this Wednesday 2: Application Layer 2.
TCP/IP (Transmission Control Protocol / Internet Protocol)
1 E- Mail. 2 Electronic Mail ( ) is simply a means of sending messages via computer Business is using more and fax To access you must.
INTERNET PROTOCOLS. Microsoft’s Internet Information Server Home Page Figure IT2031 UNIT-3.
A Quick Look At How Works Understanding the basics of how works can make life a lot easier for any user. Especially those who are interested.
CITA 310 Section 6 Providing Services (Textbook Chapter 8)
Slides based on Carey Williamson’s: FTP & SMTP1 File Transfer Protocol (FTP) r FTP client contacts FTP server at port 21, specifying TCP as transport protocol.
MCSE Guide to Microsoft Exchange Server 2003 Administration Chapter One Introduction to Exchange Server 2003.
1 Kyung Hee University Chapter 22 Simple Mail Transfer Protocol (SMTP)
Week-2 (Lecture-1) An electronic message sent from one computer to another. contains account i.e. How does.
© 2010 Computer Science Faculty, Kabul University FTP AND ELECTRONICE MAIL 5 TH LECTURE 4, May, 2010 Baseer Ahmad Baheer.
By: Derek Ton & Alex Pappas.  Most frequently used internet service that you will manage as network administrator.  You need to understand how they.
Implementing POP3 and IMAP4 Using Dovecot AfNOG 2016 Scalable Internet Services (SS-E) Gaborone, Botswana Presented by Michuki Mwangi (Built on materials.
CIW LESSON 7 PART A. INTRODUCTION TO BUSINESS ELECTRONIC MAIL The use of has given rise to the term ______________________, which is a slang term.
Spring 2006 CPE : Application Layer_ 1 Special Topics in Computer Engineering Application layer: Some of these Slides are Based on Slides.
Chapter 6 Electronic Mail. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Objectives To describe basic concepts and their specific.
Networking Applications
JavaMail Electronic Mail Concepts JavaMail Classes
Application layer tcp/ip
SMTP SMTP stands for Simple Mail Transfer Protocol. SMTP is used when is delivered from an client, such as Outlook Express, to an server.
Internet Business Associate v2.0
SMTP SMTP stands for Simple Mail Transfer Protocol. SMTP is used when is delivered from an client, such as Outlook Express, to an server.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 9
CIW Lesson 7 Part A Name: _______________________________________
Implementing POP3 and IMAP4 Using Dovecot
Simple Mail Transfer Protocol
Presentation transcript:

JavaMail JavaMail Classes Sending a Message Using JavaMail (MessageSend.java) Sending a Message to Multiple Recipients (SendToMany.java) Installing JavaMail

Protocols Message Store Protocols : Read messages from a server –Internet Message Access Protocol (IMAP) –Post Office Protocol (POP) Message Transport Protocols : Send messages to a server (i.e. Simple Mail Transfer Protocol (SMTP)) Multipurpose Internet Mail Extensions (MIME) : Standard for describing messages

Classes to Send Address: Abstract class representing any address Message: Abstract message class Header: Collection of attribute fields for a message Content: Object representing a part of a message (i.e. text or an attachment) Transport: Object representing a transport protocol that allows messages to be sent, implemented by a specific protocol Session: Provides an interface between the client and the network, supporting the creation of and access to Store and Transport objects

Specific Implementations InternetAddress: Object representing an address MimeMessage: Object representing a specific message

Store: Object representing database and access protocol for storing and accessing messages and folders, implemented by a specific protocol Folder: Contains messages and subfolders and supports reading and deleting them MailEvent: Can be registered with event listeners to catch events generated by Transport, Store, and Folder objects (i.e. announce arrival of new ) Other JavaMail Classes

Java.util.Properties Class Extends HashMap Designed to contain a persistent set of properties that may be saved to or loaded from a stream All keys and values must be Strings Although it supports HashMap methods for handling Objects, use of the following is recommended to ensure that it contains Strings: –public Object setProperty(String key, String value) –public String getProperty(String key)

Example 1: MessageSend.java Sends an address from one person to another import java.io.*; import java.net.InetAddress; import java.util.Properties; import java.util.Date; import javax.mail.*; import javax.mail.internet.*; address class Properties class will be discussed Directory containing abstract mail classes Internet classes

createSession() public Session createSession() { Properties p = System.getProperties(); p.setProperty("mail.transport.protocol", "smtp"); p.setProperty("mail.smtp.host","andrew.cmu.edu"); Gets the default system properties Sets the transport protocol to SMTP and sets the appropriate SMTP host for CMU

p.setProperty("mail.store.protocol","imap"); p.setProperty("mail.imap.host","cyrus.andrew.cmu.edu"); Session sess = Session.getDefaultInstance(p); return sess; } Instantiates a session using the new properties object Sets the store protocol to IMAP and sets the appropriate SMTP host for CMU (not really needed unless the application will read )

createMessage() public Message createMessage(Session sess) throws MessagingException{ Message mess = new MimeMessage(sess); Base exception class for Internet mail Default Constructor for a MimeMessage takes a session object

mess.setFrom(new mess.setRecipients(Message.RecipientType.TO, false)); mess.setSubject("Test"); mess.setText("This is a test of JavaMail's functionality."); mess.setSentDate(new Date()); return mess; } 2 Methods to create an InternetAddress: Constructor that takes a String: InternetAddress(String address) static InternetAddress parse(String listOfAddresses, boolean strict) (A false indicates the addresses may be space or comma delimited) setRecipients(MessageRecipientType type, String address) MessageRecipientType may be TO, CC, or BCC

main() public static void main(String[] args) { MessageSend send = new MessageSend(); Session sess = send.createSession(); try { Message mess = send.createMessage(sess); Transport.send(mess); } catch(MessagingException e) { System.out.println("Messaging Exception: "+e); } A static method of the Transport class saves and sends a message

Example 2:MessageSendToMany Sends a message to a group of addresses import java.io.*; import java.net.InetAddress; import java.util.Properties; import java.util.Date; import javax.mail.*; import javax.mail.internet.*; public class MessageSendToEach { public Session createSession() { Properties p = System.getProperties(); p.setProperty("mail.transport.protocol", "smtp"); p.setProperty("mail.smtp.host","andrew.cmu.edu"); p.setProperty("mail.store.protocol","imap"); p.setProperty("mail.imap.host","cyrus.andrew.cmu.edu"); Session sess = Session.getDefaultInstance(p); return sess; } Almost everything is the same

createMessage() public Message createMessage(Session sess)throws MessagingException, UnsupportedEncodingException { Message mess = new MimeMessage(sess); InternetAddress[] recip = new InternetAddress[6]; InternetAddress[] reply = new InternetAddress[1]; reply [0] = new “Danielle Medvan”); Note the additional exception being thrown Another constructor for an InternetAddress: InternetAddress(String address, String identifyingName) This throws an UnsupportedEncodingException if the software does not support the character encoding in which the name is provided

recip[0]= new "Gary"); recip[1]= new “Martin"); recip[2]= new “Rebecca"); recip[3]= new “Mark"); recip[4]= new “Gina"); recip[5]= new “Cameron"); mess.setFrom(new

mess.setReplyTo(reply); mess.setRecipients(Message.RecipientType.TO,recip); mess.setSubject("Test"); mess.setText("This is a test of JavaMail's functionality."); mess.setSentDate(new Date()); return mess; } The “reply-to” address is set with setReplyTo(Address[] addresses) We previously saw a method to set a single recipient. That method is overloaded. Now we see setRecipients(MessageRecipientType type, Address[] addresses)

Installation Instructions 1.Download the JavaMail API Implementation Version 1.2 at 2.Download the JavaBeans Application Framework (JAF) at: 3.Unzip both files. 4.Add the following files to your classpath: –mail.jar (JavaMail) –activation.jar (JAF file)