Posted: February 11, 2012 in Random Posts

Java Tutorials

SEND MAIL EXAMPLE

import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class TestMail {
public static void main(String args[]) throws Exception {
String host = “localhost”;
String from = “nani@gmail.com”;
String to = “nani@gmail.com”;
String user = “mallik”;
String password = “mallik”;
String content = “Change your password.”;
Properties properties = System.getProperties();
properties.setProperty(“mail.smtp.host”, host);
Session session =Session.getDefaultInstance(properties);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject(“Test Mail”);
message.setText(content);

Transport.send(message);
System.out.println(“Message Send Successfully…” + content);

}
}

READING MAIL EXAMPLE

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

public class ReadMail {
public static void main(String args[]) throws Exception {
String host = “localhost”;
String user = “nani”;
String password = “nani”;
Properties properties = System.getProperties();
Session session = Session.getDefaultInstance (properties);
Store store = session.getStore(“pop3”);
store.connect(host, user, password);
Folder folder = store.getFolder(“inbox”);
folder.open(Folder.READ_ONLY);

Message[] message = folder.getMessages();

for (int i = 0; i < message.length; i++)…

View original post 227 more words

Advertisements
Comments
  1. Leonard Hapke says:

    I like this web site very much, Its a rattling nice place to read and get information. “I am always afraid of your something shall be done.” by Titus Maccius Plautus.

  2. eliminating credit card bills says:

    Hello, Neat post. There is an issue together with your site in internet explorer, would test thisÖ IE nonetheless is the marketplace chief and a huge component of other people will leave out your fantastic writing due to this problem.

  3. Victoria secret credit card says:

    I like what you guys are up also. Such clever work and reporting! Keep up the excellent works guys I have incorporated you guys to my blogroll. I think it will improve the value of my site :).

  4. community health education says:

    Hey, you used to write wonderful, but the last few posts have been kinda boringÖ I miss your great writings. Past several posts are just a bit out of track! come on!

  5. blackjack games online says:

    I enjoy the efforts you have put in this, thank you for all the great posts.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s