Advance Java

JavaMail Projects

JavaMail Project 1

JavaMail Interview Questions And Answers


Totel:15 Click: 1 2 3
JavaMail Interview Questions And Answers

Page 1

If you want to Delete a Message or Mail for Using Java Mail API. Then you using a method call for deleting messages call setFlag() on set the message and set the Flags.Flag.DELETED flag is true.

message.setFlag(Flags.Flag.DELETED, true);

When you close the folder, deleted message will be removed. then be sure the open the folder for read/write access

folder.open(Folder.READ_WRITE);

public class deletemail{

public static void main (String args[]) throws Exception {

String host = args[0];

String username = args[1];

String password = args[2];

// Get session

Session session = Session.getInstance(

System.getProperties(), null);

// Get the store

Store store = session.getStore("pop3");

store.connect(host, username, password);

// Get folder

Folder folder = store.getFolder("INBOX");

folder.open(Folder.READ_WRITE);

BufferedReader reader = new BufferedReader (

new InputStreamReader(System.in));

// Get directory

Message message[] = folder.getMessages();

for (int i=0, n=message.length; i<n; i++) {

System.out.println(i + ": " + message[i].getFrom()[0] 

+ "t" + message[i].getSubject());

System.out.println("Do you want to delete message? [YES to delete]");

String line = reader.readLine();

// Mark as deleted if appropriate

if ("YES".equals(line)) {

message[i].setFlag(Flags.Flag.DELETED, true);

}

}

// Close connection 

folder.close(true);

store.close();

}

}

The MultiPart Mail is like a special type container. And this Multi Part container holds one or more body Parts. When you want to send a Multi Part Mail then firstly create a Multi Part class object, after create a BodyPart class object, you set total text in class BodyPart class object and all BodyPart class object in Multipart class object and send the message. In Abstract class in use code for Multi Part class. The using method in this MultiPart class is  void addBodyPart(BodyPart part);

Yes, If you want to send  images then attach images in to your Mesages and then send. you using JavaMail API attach your image. This images attachment and  reference the image with a special cid URL, where the cid is a reference to the Content-ID header of the image attachment. The attaching images or embedding images on your messages like as similar to attaching the file in your message. The only difference for you have to tell the MimeMultipart that the part are related by setting it's subtype. The subtype in the Constructor or setSubType () and set the Content-ID header for the image to a random string which is used as the src for the image in the img tag. The following demonstrates this completely.

When you want to forward Mails or Messages. for directly forwarding for one or many E-mails. Then in Forwarding Messages is a little more involved. You forwarding the message for using JavaMail API. there is no only one method to call .Actually a Mail Messages can be made up of multiple parts. The Every part is BodyPart, or more specifically, and when working you MIME Messages then a MimeBodyPart. the other or different BodyPart is get combined into a container, this container also called Multipart or, again, more specifically a MimeMultipart. When forwarding messages then it's very essentially using DataHandler. to copy the content one message to another, just copy over it's DataHandler. The DataHandler class from JavaBean Activation Framework.

For Reading mail you get a session get and connect to your appropriate store for your mailbox, then pen your appropriate folder , and get your message. when totally operation perform then don't forget to close to connection.

public class FetchMsg 

{

public static void main(String args[]) throws Exception

{

String host="192.168.10.255";

String username = "r4r@localhost";

String password = "r4r@localhost"; 

// Create empty properties

Properties props = new Properties();

// Get session

Session session = Session.getDefaultInstance(props, null);

// Get the store

Store store = session.getStore("pop3");

store.connect(host, username, password);

// Get folder

Folder folder = store.getFolder("INBOX");

folder.open(Folder.READ_ONLY);

BufferedReader reader = new BufferedReader (

new InputStreamReader(System.in));

// Get directory

Message message[] = folder.getMessages();

for (int i=0, n=message.length; i<n; i++) {

System.out.println(i + ": " + message[i].getFrom()[0] 

+ "t" + message[i].getSubject());

System.out.println("Do you want to read message? " +

"[YES to read/QUIT to end]");

String line = reader.readLine();

{

if ("YES".equals(line)) 

message[i].writeTo(System.out);

else if ("QUIT".equals(line)) 

break; }

}

}}


Goto Page:

1 2 3
JavaMail Objective Questions And Answers

JavaMail Objective Questions And Answers

JavaMail Interview Questions And Answers

JavaMail Subjective Questions And Answers


R4R,JavaMail Objective fresher and experienced, JavaMail Subjective fresher and experienced ,JavaMail Interview Questions And Answers,JavaMail fresher and experienced,JavaMail Interview fresher and experienced ,JavaMail Questions fresher and experienced,JavaMail Answers fresher and experienced