Sending message using Java Mail
This Example shows you how to send a message using javamail api. A client create new message by using Message subclass. It sets attributes like recipient
address and the subject, and inserts the content into the Message object, and inserts the content into
the Message object. Finally, it sends the Message by invoking the Transport.send() method.
The Transport class models the transport agent that routes a message to its destination addresses. This class provides methods that send a message to a list of recipients. Invoking the Transport.send() method with a Message object identifies the appropriate transport based on its destination addresses.
SendMail.java
import java.util.*; import javax.mail.*; import javax.mail.internet.*; public class SendMail { public static void main(String args[]) throws Exception { String host = "192.168.10.205"; // Get system properties // Setup mail server // Get the default Session object.
// Create a default MimeMessage object. // Set the RFC 822 "From" header field using the // Add the given addresses to the specified recipient type. // Set the "Subject" header field. // Sets the given String as this part's content, // Send message System.out.println("Message Send....."); |
Output:
Message Send..... |