import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
public class Assimilator {
public static void main(String args[]) throws Exception {
String host = "192.168.10.205";
Address from = new
InternetAddress("test@localhost", "test");
Address to = new
InternetAddress("test@localhost");
// Get system properties
Properties properties =
System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host",
host);
// Get the default Session object.
Session session =
Session.getDefaultInstance(properties);
// Create a default MimeMessage object.
Message msg = new
MimeMessage(session);
// Set the RFC 822 "From" header field using the
// value of the
InternetAddress.getLocalAddress method.
msg.setFrom(from);
// Add the given addresses to the specified recipient type.
msg.addRecipient(Message.RecipientType.TO,
to);
// Set the "Subject" header field.
msg.setSubject("Resistance is futile.");
// Sets the given String as this part's content,
// with a MIME type of
"text/plain".
msg.setContent("Resistance
is futile. You will be assimilated!" , "text/plain");
//Send mail
Transport.send(msg);
System.out.println("msg
send...");
}
} |