Java Training Introduction to Java Mail Written by Jeff Smith.

Slides:



Advertisements
Similar presentations
6 C H A P T E R © 2001 The McGraw-Hill Companies, Inc. All Rights Reserved1 Electronic Mail Electronic mail has revolutionized the way people communicate.
Advertisements

Topic : JavaMail API (1) Sending and Receiving s Kaster Nurmukan.
How Clients and Servers Work Together. Objectives Web Server Protocols Examine how server and client software work Use FTP to transfer files Initiate.
J2EE JavaMail API Presented by Bartosz Sakowicz. Instalation Java Mail API: Java Activation Framework.
Remote mailbox access gateway Software lab project.
CPSC 441: FTP & SMTP1 Application Layer: FTP & Instructor: Carey Williamson Office: ICT Class.
Exchange server Mail system Four components Mail user agent (MUA) to read and compose mail Mail transport agent (MTA) route messages Delivery agent.
COS/PSA 413 Day 17. Agenda Lab 8 write-up grades –3 B’s, 1 C and 1 F –Answer the Questions!!! Capstone progress report 2 overdue Today we will be discussing.
How Clients and Servers Work Together. Objectives Learn about the interaction of clients and servers Explore the features and functions of Web servers.
Technion – Israel Institute of Technology Department of Electrical Engineering Software Lab Remote Mailbox based on.NET technology Michael and Eugene Shamis.
Introduction to the Secure SMTP Server service. Secure SMTP server is a secure, reliable SMTP mail relay server for your outgoing mail. Secure SMTP service.
Guide to Operating System Security Chapter 10 Security.
CSCI 6962: Server-side Design and Programming Server Created .
POP Configuration Microsoft Outlook Express 6.x.
CLIENTS Advantages Setup Features. Advantages Allows programs and websites to use “default ” Scanners Picture Programs Word Processing programs.
2440: 141 Web Site Administration Services Instructor: Enoch E. Damson.
Introduction 1 Lecture 7 Application Layer (FTP, ) slides are modified from J. Kurose & K. Ross University of Nevada – Reno Computer Science & Engineering.
Pro Exchange SPAM Filter An Exchange 2000 based spam filtering solution.
Sending and Receiving s
-I CS-3505 Wb_ -I.ppt. 4 The most useful feature of the internet 4 Lots of different programs, but most of them can talk to each.
POP Configuration Microsoft Outlook What is POP? Short for Post Office Protocol, a protocol used to retrieve from a mail server. Most.
E – Mail History of s What is an ? What happens when we sent an ? messages Folders Address Attachments Types of.
Managing Client Access
Module 4 Managing Client Access. Module Overview Configuring the Client Access Server Role Configuring Client Access Services for Outlook Clients Configuring.
IT:Network:Applications Fall  Running one “machine” inside another “machine”  OS in Virtual machines sees ◦ CPU(s) ◦ Memory ◦ Disk ◦ USB ◦ etc.
Section 6.1 Explain the development of operating systems Differentiate between operating systems Section 6.2 Demonstrate knowledge of basic GUI components.
Computer Concepts 2014 Chapter 7 The Web and .
1 Web Server Administration Chapter 8 Providing Services.
Chapter 7: Using Windows Servers to Share Information.
Mail Services.
IT 424 Networks2 IT 424 Networks2 Ack.: Slides are adapted from the slides of the book: “Computer Networking” – J. Kurose, K. Ross Chapter 2: Application.
Intro to Computer Networks Bob Bradley The University of Tennessee at Martin.
The Linux Operating System Lecture 7: Tonga Institute of Higher Education.
Fall 2005 By: H. Veisi Computer networks course Olum-fonoon Babol Chapter 7 The Application Layer.
Computer Networking From LANs to WANs: Hardware, Software, and Security Chapter 12 Electronic Mail.
MCSE Guide to Microsoft Exchange Server 2003 Administration Chapter Four Configuring Outlook and Outlook Web Access.
Webmail. Agenda Why use webmail? Why use webmail? What is webmail What is webmail – basic » system MDA MDA MTA MTA MUA MUA »Protocol SMTP SMTP.
WXET1143 Lecture7: , Chat and Messaging. Introduction  Electronic mail is everywhere.  Now many people in business, government, and education use.
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.
(or ?) Short for Electronic Mail The transmission of messages over networks.
Electronic Mail. Client Software and Mail Hosts –Client PC has client software that communicates with user’s mail host –Mail hosts deliver.
File Transfer Protocol (FTP)
Chapter 3: Services of Network Operating Systems Maysoon AlDuwais.
Concepts  messages are passed through the internet by using a protocol called simple mail transfer protocol.  The incoming messages are.
The Internet 8th Edition Tutorial 3 Using Web-Based Services for Communication and Collaboration.
P.O.P. A presentation brought to you by Thomas. Topics Introduction General Information Area of use Functionality The alternative way POP3 vs. IMAP Conclusion.
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.
RYAN HICKLING. WHAT IS AN An messages distributed by electronic means from one computer user to one or more recipients via a network.
4343 X2 – Outline The Domain Name System The Web.
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.
Linux Operations and Administration Chapter Twelve Configuring a Mail Server.
MCSE Guide to Microsoft Exchange Server 2003 Administration Chapter One Introduction to Exchange Server 2003.
VIRTUAL SERVERS Chapter 7. 2 OVERVIEW Exchange Server 2003 virtual servers Virtual servers in a clustering environment Creating additional virtual servers.
Outlook / Exchange Training. Outlook / Exchange: Agenda What Can Microsoft Exchange Do / How works at UST? and Inbox Mailbox Quota Archiving.
Microsoft Virtual Academy Talbott Crowell | Chief Architect, ThirdM.com Rob Latino | Program Manager in Office 365 Support, Microsoft.
Week-2 (Lecture-1) An electronic message sent from one computer to another. contains account i.e. How does.
1 Outlook web app مریم جعفری. Preface 2 Webmail (or web-based ) is any client implemented as a web application running on a web server. Examples.
Spring 2006 CPE : Application Layer_ 1 Special Topics in Computer Engineering Application layer: Some of these Slides are Based on Slides.
APACHE Apache is generally recognized as the world's most popular Web server (HTTP server). Originally designed for Unix servers, the Apache Web server.
Chapter 7: Using Windows Servers
Network Programming 10- SMTP-POP3
Networking Applications
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.
SUBMITTED BY: NAIMISHYA ATRI(7TH SEM) IT BRANCH
CompTIA Server+ Certification (Exam SK0-004)
has many aspects that work together to give people almost instant communication from any computer on the internet to any other computer There.
Simplifying the Java Mail API
Presentation transcript:

Java Training Introduction to Java Mail Written by Jeff Smith

What is JavaMail? -1 n JavaMail is an API for sending and receiving using Java. The current version is and can be downloaded from Sun's website at: n Possible uses: n Send from web pages using servlets n Create a GUI client n Send from Java stored procedures n Send from any type of Java application n Spam your friends and enemies! (read addresses from a database, write a for () loop, and away the s go!)

What is JavaMail? -2 n To send JavaMail, you'll need to add at least two JAR files from Sun to your classpath (placing them in a lib directory may be a good idea) n activation.jar n mail.jar (Note: You can download these files from the Java Zone) n For more complex ing tasks (like receiving or managing pop3 or imap mail servers), you'll need to download additional files like pop3.jar and imap.jar. n You will also need access to a mail server and possibly a username/password for that mail server

How Does Work? n In general, each internet domain has an server. n When you send out an n Your client program sends the message to your server n Your server contacts the addressee's server using the SMTP (simple mail transfer protocol) n Your server verifies that the addressee's user name is valid n Your server then transfers the to the addressee's server n When the addressee logs into his server (using his client program), he gets his

Mail Servers (sendmail)-1 n sendmail is the most commonly used mail server in the world, as it generally comes free with Unix and Linux installations n very powerful and flexible. Supports POP3 and IMAP n well documented (lots of books on setting up sendmail) n long track record (first version appeared in early '80s) n tedious to set up (lots of cryptic configuration files) n free n

Mail Servers (qmail)-2 n qmail is probably the most popular alternative to sendmail in the UNIX world n perhaps more secure than sendmail (at least older versions of sendmail) n Easier to set up and administer than sendmail n pretty good documentation (several books written on qmail in the past few years) n free n

Mail Servers (MS Exchange)-2 n MS Exchange is widely used in the Windows world, especially in corporate environments that use MS Office (and hence MS Outlook) n Expensive n Integrated into MS Active Directory n GUI administration tools are easier to learn for Windows people n MS Outlook is a powerful and slick program that will work with Exchange, sendmail, or qmail. It does, however, have a history of security vulnerabilities and some organizations refuse to use it because of that.

POP3, IMAP, MAPI -1 n Currently, the most popular protocols are n POP3 (Post Office Protocol, version 3) n IMAP (Internet Message Access Protocol) n MAPI (Messaging Application Programming Interface-- Microsoft Windows interface)

POP3 n POP3 is the oldest and most widely used. It was designed to support offline mail processing. n Mail is delivered to a server and a user's computer runs a mail client program to download any new mail n Once messages are delivered, they are generally deleted from the mail server n This minimizes disk space requirements for mail server, but ties the mail to a particular machine. If user goes to another computer, he can't access his mail n POP3 has limited support for reading mail online (and leaving the mail on the mail server) n Simpler protocol than IMAP makes it easier to implement. More POP3 mail clients available

IMAP n IMAP n Developed at University of Washington n Primarily used to access mail and leave it on the mail server. This allows users to access their mail from any computer n Requires more disk space to store messages n Can work in "offline" mode like POP3 n Easy to manage multiple mailboxes n Supports tagging s with flags like "read", "deleted", "answered", etc.

MAPI n MAPI n Set of C functions (API) developed by Microsoft and supported in MS Exchange/Outlook n Also supported by Eudora Mail n For more info, type the following search string in Google: "MAPI site:msdn.microsoft.com"

Apache James Mail Server n Apache has a free mail server called James n Supports POP3, SMTP, and NNTP n Download the binary file n.ZIP version (for Windows) n.TAR version (for Linux) n Uncompress it and then run “run.bat” (Windows) or “run.sh” (Linux) to start the mail server Download from here:

NOAA Mail Server n You can use ESRL/NOAA’s server .boulder.noaa.gov mailProperties.setProperty("mail.smtp.host"," .boulder.noaa.gov"); n This will work IF you send s addresses (like n When I tried to send an to I got this error message Invalid Address Relaying not allowed:

Using JavaMail -1 n Once you have a mail server you can use (either James or another mail server), you can send s through it by using JavaMail n In general, to send a plain text using JavaMail, you do the following: n Get a mail session instance n Create a MimeMessage object (passing in the mail session instance into the constructor) n Set the MimeMessage object's properties (like the toAddress, fromAddress, message, etc.) n Send the message

Getting a Mail Session n Get a mail session for the James mail server. If James is running on your own computer, your mail.smtp.host is localhost. n If your mail server is a remote computer, it might be something like “mailgate.fsl.noaa.gov” n Get a mail session for the James mail server private Session getMailSession() throws Exception { Properties mailProperties = new Properties(); mailProperties.setProperty("mail.transport.protocol", "smtp"); mailProperties.setProperty("mail.smtp.host", " localhost"); return Session.getInstance(mailProperties, null); }

Plain Text Example n Next, send your using the mail session MimeMessage msg = new MimeMessage(getMailSession()); msg.setFrom(new msg.addRecipient(Message.RecipientType.TO, new msg.setSubject("RE: Oracle vs SQL Server"); msg.setText("SQL Server is better than Oracle"); Transport.send(msg);

Exceptions and imports n Your code which sends an will need to catch the following checked exceptions: n Exception n MessagingException n AddressException n You should import the following packages: import javax.mail.*; import javax.mail.internet.*;

HTML n You can also send HTML with JavaMail. HTML can be used to n Use different size fonts n imbed images into your n Use different colored text, bold, italic, etc.

HTML n With HTML , n you set the mime message content type to "text/html" n call the setContent() method to set your html content n It helps to know a little HTML!

Mail Security n Virtually all mail servers require a username and password to receive n Some mail servers require a username and password to send an (by default, James does not). n This prevents spammers from hijacking the mail server to send unauthorized n JavaMail supports this username/password authorization and authentication n To implement this, you get a transport object from the mail session and call the connect() method with the mail host, username, and password n See next slide for code example

HTML Example n Example of sending html message with an imbedded image using username/password authorization MimeMessage msg = new MimeMessage(mailSession); msg.setFrom(new msg.addRecipient(Message.RecipientType.TO, new msg.setSubject(subject); String html = " MY SPAM <img src=' "; msg.setContent(html, "text/html"); Transport transport = mailSession.getTransport("smtp"); transport.connect("localhost","user", "passwd"); msg.saveChanges(); transport.sendMessage(msg, msg.getAllRecipients()); transport.close();

attachments -1 n To append an attachment, you need to send a "multipart" message n Create your MimeMessage object as usual, setting the from address, to address, subject, etc... n Create a MimeBodyPart object for your main message and set its text (or content) to be your message n Create a MimeMultiPart object for your attachment and call its setContent() method to attach your file n Create a Multipart object and add both body parts to it. n Call your MimeMessage's setContent() method, passing in your Multipart object n Call Transport.send() to send the message n Whew!!!

attachment Example-1 MimeMessage msg = new MimeMessage(getMailSession()); msg.setFrom(new msg.addRecipient(Message.RecipientType.TO, new msg.setSubject("RE: Oracle vs SQL Server"); //Create the main message (body) part MimeBodyPart mainBodyPart = new MimeBodyPart(); mainBodyPart.setText("Here is my message");

attachment Example-2 //Create attachment body part MimeBodyPart attachBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource("1.jpg"); attachBodyPart.setDataHandler(new DataHandler(source)); attachBodyPart.setFileName("1.jpg"); //Now create the multipart and add the parts Multipart multipart = new MimeMultipart(); multipart.addBodyPart(mainBodyPart); multipart.addBodyPart(attachBodyPart); //add the multipart to the original Mime message msg.setContent(multipart); Transport.send(msg);

Exercise -1 n Write a program in package gov.noaa. that reads a list of recipients from a disk file and then sends them each an message. n Use your NOAA webmail account to test this (or you can use our Yahoo account) n You'll need to: n Create a file and populate it with a list of addresses (use your own address or someone else in the class) n Send a single to all the recipients you read from the db table. n If you are feeling ambitious, you can send an HTML message. n Use an client (NOAA webmail?) to verify message delivery n Extra credit: send an attachment and write an Ant script for your project

JavaMail Summary n JavaMail is powerful with good support for things like HTML and attachments n But adding an attachment isn't as simple as it should be. A nice framework (or helper class) would be useful to simplify JavaMail code n JavaMail also supports n receiving n administering mail servers For an article on receiving via JavaMail, see: javamail-p2.html