GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Programming  >  Java Classes
Go To First  |  Previous Question  |  Next Question 
 Java Classes  |  Question 64 of 68    Print  
how to send email using java?

  
Total Answers and Comments: 1 Last Update: January 17, 2009     Asked by: baba 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 16, 2009 23:33:51   #1  
vijays Member Since: October 2008   Contribution: 3    

RE: how to send email using java?
Java Mail API is ued to send a Mail through java application. To Test Program all you need to have is a SMTP address (Which your ISP Provides).

We will see a sample program to send a mail through java program now.

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public void postMail( String recipients[ ] String subject String message String from) throws MessagingException
{
boolean debug false;

//Set the host smtp address
Properties props new Properties();
props.put( mail.smtp.host Replace this with your ISP's SMTP address
);


// create some properties and get the default Session
Session session Session.getDefaultInstance(props null);
session.setDebug(debug);

// create a message
Message msg new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom new InternetAddress(from);
msg.setFrom(addressFrom);

InternetAddress[] addressTo new InternetAddress[recipients.length];
for (int i 0; i < recipients.length; i++)
{
addressTo[i] new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO addressTo);

// Optional : You can also set your custom headers in the Email if you Want
msg.addHeader( MyHeaderName myHeaderValue );

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message text/plain );
Transport.send(msg);
}


 
Is this answer useful? Yes | No

 Related Questions

A) TrueB) False 
Latest Answer : flase ...

A) TrueB) False 
Latest Answer : Code in Java can also be in instance initializer blocks and static and non-static blocks. So the answer to this question is false. ...

A) TrueB) False 
Latest Answer : I think it is true. Because, we use initalize some variables which are not dynamic.For eg: int i = 10; ...

A) ArgumentsB) ClassesC) ConstructorsD) Parameters 
Latest Answer : Yes objects can be created only using constructors if we do not provide one compiler will create a default cons for us thus allocating memory for objects we are going to create and the default values for instance variables are:for integers, float, double, ...

Sometimes a method will need to refer to the object that invoked it. To allow this, Java defines the_____ keyword
A) this B) thatC) theD) and 

A) TrueB) False 
Latest Answer : True, deallocation is called Garbage Collection ...

In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different
A) TrueB) False 

A) EncapsulationB) ClassC) InheritenceD) Polymorphism 
Latest Answer :      With method overloading Java supports polymorphism. ...

When an overloaded method is invoked, Java uses the type and/or number of arguments as its guide to determine which version of the overloaded method to actually call
A) TrueB) False 

A) TrueB) False 
Latest Answer : false ...


 Sponsored Links

 
Related Articles

Service Oriented Java Business Integration Review

Service Oriented Java Business Integration Review Introduction If you ve read through the texts which give you an introduction to SOA or Web Services you will often find them to be quite frustrating and the reason for this is because they spend too much time referencing business processes which are
 

ODP.NET - Fundamental ODP.NET Classes to Retrieve Data

ODP NET Fundamental ODP NET Classes to Retrieve Data To retrieve data from an Oracle database using ODP NET we need to work with a few of the ODP NET classes At this point we will discuss the most fundamental classes available in ODP NET for retrieving data mosgoogle The following is the list of fun
 

Microsoft AJAX Library - C# and JavaScript Classes

C and JavaScript Classes For the purpose of demonstrating a few more OOP related concepts we ll use another class Our new class is named Table and it has two public fields rows columns and one method getCellCount The getCellCount method should return the number of rows multiplied by the number of co
 

Microsoft AJAX Library - JavaScript Classes

JavaScript Classes Not only can JavaScript functions contain other functions but they can also be instantiated This makes JavaScript functions a good candidate for implementing the concept of a class from traditional object oriented programming This is very helpful feature indeed because JavaScript
 

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

C++ Storage Classes

C Storage Classes In this C tutorial you will learn about storage classes types of storage class variables Automatic External and Static explained with examples mosgoogle center Storage classes In the context of scope of variables in functions exists the important concept of storage class What is St
 

Java and Client Server Models

Java and Client Server Models The Role of Client Servers on the Web Client server models provide the essential mechanisms for working with the Internet In fact most of the World Wide Web is built according to this paradigm In client server models the web browsers run by millions of users are the cli
 

C++ Objects and Classes

C Objects and Classes An Overview about Objects and Classes In object oriented programming language C the data and functions procedures to manipulate the data are bundled together as a self contained unit called an object A class is an extended concept similar to that of structure in C programming l
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school&rsquo;s al
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape