How to go send java mail from localhost

To send a Java mail from localhost, you'll need to follow these steps:

Step 1: Set up your Java project

Step 3: Write your Java code

Here's the complete code:

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendMail {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("mail.smtp.host", "localhost");
        props.put("mail.smtp.port", "2525");
        props.put("mail.smtp.auth", "true");

        Session session = Session.getInstance(props, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("your-email-address", "your-password");
            }
        });

        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress("your-email-address"));
        message.setRecipient(Message.RecipientType.TO, new InternetAddress("recipient-email-address"));
        message.setSubject("Test Mail");
        message.setText("This is a test mail sent from localhost");

        Transport.send(message);
    }
}

Remember to replace your-email-address, your-password, and recipient-email-address with your actual email credentials and the recipient's email address.