3

我正在尝试使用 to、cc 和 bcc 发送邮件。我正在使用 javax.mail 来实现这一点。请在下面找到我的代码的一部分

InternetAddress[] myToList = InternetAddress.parse("gopi.mani@xyz.com,Maimsa.SF@xyz.com");
InternetAddress[] myBccList = InternetAddress.parse("Usha.B@xyz.com");
InternetAddress[] myCcList = InternetAddress.parse("NEHA.SIVA@xyz.com");
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(objEmail.getFrom()));
message.setRecipients(Message.RecipientType.TO,myToList);
message.setRecipients(Message.RecipientType.BCC,myBccList);
message.setRecipients(Message.RecipientType.CC,myCcList);

但是当我尝试执行此代码时,出现以下异常:

javax.mail.SendFailedException:无效地址;
嵌套异常是:
com.sun.mail.smtp.SMTPAddressFailedException: 452 4.5.3 收件人太多

4

2 回答 2

8

尝试这个

InternetAddress[] myToList = InternetAddress.parse("gopi.mani@xyz.com,Maimsa.SF@xyz.com");
InternetAddress[] myBccList = InternetAddress.parse("Usha.B@xyz.com");
InternetAddress[] myCcList = InternetAddress.parse("NEHA.SIVA@xyz.com");
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(objEmail.getFrom()));
message.setRecipients(Message.RecipientType.TO,myToList);
// changes,...
message.addRecipient(Message.RecipientType.BCC,myBccList);
message.addRecipient(Message.RecipientType.CC,myCcList);
于 2013-12-05T14:46:47.090 回答
1
InternetAddress[] toAddress = new InternetAddress[to.length];

        // To get the array of toaddresses
        for( int i = 0; i < to.length; i++ ) {
            toAddress[i] = new InternetAddress(to[i]);
            message.addRecipient(Message.RecipientType.TO, toAddress[i]);
        }

        InternetAddress[] ccAddress = new InternetAddress[cc.length];

        // To get the array of ccaddresses
        for( int i = 0; i < cc.length; i++ ) {
            ccAddress[i] = new InternetAddress(cc[i]);
            message.addRecipient(Message.RecipientType.CC, ccAddress[i]);
        }

        InternetAddress[] bccAddress = new InternetAddress[bcc.length];

        // To get the array of bccaddresses
        for( int i = 0; i < bcc.length; i++ ) {
            bccAddress[i] = new InternetAddress(bcc[i]);
            message.addRecipient(Message.RecipientType.BCC, bccAddress[i]);
        }

如果您需要使用 CC 或 BCC,则不是我们的 .setRecipients

于 2019-01-30T20:22:50.860 回答