在Java中,我们可以使用JavaMail API来实现发送多人邮件单独显示分别发送的功能。JavaMail API提供了一种灵活的方式来发送电子邮件,包括设置收件人、主题、内容等信息。下面我们将通过一个示例来演示如何实现这一功能。

首先,我们需要导入JavaMail API的相关依赖包。可以通过 Maven 来添加以下依赖:

<dependency>
    <groupId>com.sun.mail</groupId>
    <artifactId>javax.mail</artifactId>
    <version>1.6.2</version>
</dependency>
<dependency>
    <groupId>javax.mail</groupId>
    <artifactId>javax.mail-api</artifactId>
    <version>1.6.2</version>
</dependency>

然后,我们可以编写一个Java类来实现发送多人邮件单独显示分别发送的功能。以下是一个示例代码:

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class EmailSender {

    public static void main(String[] args) {

        final String username = "your-email@gmail.com";
        final String password = "your-password";

        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");

        Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username, password);
                    }
                });

        try {
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("your-email@gmail.com"));
            message.setSubject("Test Email");

            Address[] recipients = new Address[]{
                    new InternetAddress("recipient1@example.com"),
                    new InternetAddress("recipient2@example.com"),
                    new InternetAddress("recipient3@example.com")
            };

            for (Address recipient : recipients) {
                message.setRecipient(Message.RecipientType.TO, recipient);
                message.setText("This is a test email for " + recipient);
                Transport.send(message);
                System.out.println("Email sent to " + recipient);
            }

        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}

在上面的代码中,我们首先设置发送邮件的账号和密码,以及邮件服务器的配置信息。然后创建一个邮件会话,并设置邮件的发送者、主题等信息。接着创建一个收件人的数组,分别设置每个收件人并发送邮件。最后通过Transport.send()方法发送邮件。

需要注意的是,循环中的每次设置收件人和发送邮件都会新建一个MimeMessage对象,以确保每封邮件都会单独显示分别发送。

通过以上代码,我们可以实现在Java中发送多人邮件单独显示分别发送的功能。这种方法可以确保每个收件人都会单独收到一封邮件,而不会共享其他收件人的信息。

在实际应用中,可以根据需要修改邮件的内容、附件等信息,以满足具体的业务需求。

综上所述,通过JavaMail API可以很方便地实现发送多人邮件单独显示分别发送的功能,为我们的邮件发送提供了更加灵活和定制化的方式。希望以上内容对您有所帮助。