@@ -0,0 +1,2479 @@
+package sporadic;%0A%0Aimport java.util.Properties;%0A%0Aimport javax.mail.Message;%0Aimport javax.mail.MessagingException;%0Aimport javax.mail.Session;%0Aimport javax.mail.Transport;%0Aimport javax.mail.internet.InternetAddress;%0Aimport javax.mail.internet.MimeMessage;%0A%0A//TODO: make this program work!%0A%0A/**%0A * To send an e-mail using your Java Application is simple enough but to start%0A * with you should have JavaMail API and Java Activation Framework (JAF)%0A * installed on your machine.%0A * %0A * %5BDONE%5D You can download latest version of JavaMail (Version 1.2) from Java's%0A * standard website.%0A * %0A * %5BDONE%5D You can download latest version of JAF (Version 1.1.1) from Java's%0A * standard website.%0A * %0A * Download and unzip these files, in the newly created top level directories%0A * you will find a number of jar files for both the applications. You need to%0A * add mail.jar and activation.jar files in your CLASSPATH.%0A * %0A * Send a Simple E-mail: Here is an example to send a simple e-mail from your%0A * machine.%0A * %0A * Here it is assumed that your localhost is connected to the internet and%0A * capable enough to send an email.%0A */%0A%0A// This app is not running now, I guess it's b/c my localhost is not connected%0A// to Internet yet. I need to figure this out.%0Apublic class SendEmail %7B%0A%0A%09public static void main(String%5B%5D args) %7B%0A%09%09// Recipient's email ID needs to be mentioned.%0A%09%09String to = %22sunjiahuan@gmail.com%22;%0A%0A%09%09// Sender's email ID needs to be mentioned%0A%09%09String from = %22steve.j.sun@gmail.com%22;%0A%0A%09%09// Assuming you are sending email from localhost%0A%09%09String host = %2210.34.128.145%22;%0A%0A%09%09// Get system properties%0A%09%09Properties properties = System.getProperties();%0A%0A%09%09// Setup mail server%0A%09%09properties.setProperty(%22mail.smtp.host%22, host);%0A%0A%09%09// Get the default Session object.%0A%09%09Session session = Session.getDefaultInstance(properties);%0A%0A%09%09try %7B%0A%09%09%09// Create a default MimeMessage object.%0A%09%09%09MimeMessage message = new MimeMessage(session);%0A%0A%09%09%09// Set From: header field of the header.%0A%09%09%09message.setFrom(new InternetAddress(from));%0A%0A%09%09%09// Set To: header field of the header.%0A%09%09%09message.addRecipient(Message.RecipientType.TO, new InternetAddress(%0A%09%09%09%09%09to));%0A%0A%09%09%09// Set Subject: header field%0A%09%09%09message.setSubject(%22This is the Subject Line!%22);%0A%0A%09%09%09// Now set the actual message%0A%09%09%09message.setText(%22This is actual message%22);%0A%0A%09%09%09// Send message%0A%09%09%09Transport.send(message);%0A%09%09%09System.out.println(%22Sent message successfully....%22);%0A%09%09%7D catch (MessagingException mex) %7B%0A%09%09%09mex.printStackTrace();%0A%09%09%7D%0A%09%7D%0A%7D%0A

send email in java example