Javax.mail.message

javax.mail.Message is a class in the JavaMail API that represents an email message. It is the top-level class for all email messages and provides methods for setting and getting various attributes of the message, such as the sender, recipient, subject, and body.

Here are some key methods and attributes of the Message class:

Attributes:

Methods:

Example usage:

Here is an example of how to create a new Message object and set its attributes:

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

// Create a new message
Message msg = new MimeMessage(session);

// Set the sender
msg.setFrom(new InternetAddress("[email protected]"));

// Set the recipient
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));

// Set the subject
msg.setSubject("Test email");

// Set the content
msg.setText("This is a test email");

// Send the message
Transport.send(msg);

In this example, we create a new MimeMessage object using the Session object, set the sender, recipient, subject, and content, and then send the message using the Transport object.