how to write a program for sending mails between client and
server



how to write a program for sending mails between client and server..

Answer / Deep Kumar

To send emails between a client and a server using Java, you can use the JavaMail API as mentioned in the previous answer. In this case, however, the server will need to have a separate process running to handle incoming emails.nnOn the client side, the code for sending an email remains the same. On the server side, you'll need to set up a Java program that listens for incoming emails and handles them accordingly. Here's an example of how to receive an email using a separate Java thread:n
1. First, create a class for handling incoming emails:n```java
import javax.mail.*;
import java.io.IOException;
import java.util.Properties;
npublic class EmailReceiver {
public static void main(String[] args) throws MessagingException {
Properties props = System.getProperties();
props.put("mail.store.protocol", "imaps");
Session session = Session.getDefaultInstance(props);
Store store = session.getStore("imaps");
store.connect("your_imap_server");
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);

Message[] messages = inbox.search(new FlagTerm(new Flags.Flag.InstantiatedFlag(Flags.Flag.SEEN), false));
for (Message message : messages) {
// Process the email here
}
}n}n```
2. To process incoming emails, you can extract relevant information such as the sender, subject, and body of the email and take appropriate actions based on your requirements.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is rule of accessibility in java?

1 Answers  


Explain about narrowing conversion in java?

1 Answers  


What if static is removed from main method?

1 Answers  


Can we catch more than one exception in single catch block?

1 Answers  


What the difference is between execute, execute Query, execute Update?

1 Answers  


Explain about core java?

1 Answers  


What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. Import java.net.* Versus import java.net.socket)?

1 Answers  


Why put method is used?

1 Answers  


What is the biggest integer?

1 Answers  


write a code, we have two thread, one is printing even no and other print the odd no.

1 Answers   Global Logic,


What is the final field modifier?

1 Answers  


What are the basic control structures?

1 Answers  


Categories