Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带收件人、抄送和密件抄送的Java邮件_Java_Email_Bcc_Carbon Copy - Fatal编程技术网

带收件人、抄送和密件抄送的Java邮件

带收件人、抄送和密件抄送的Java邮件,java,email,bcc,carbon-copy,Java,Email,Bcc,Carbon Copy,我正在尝试用收件人、抄送和密件抄送发送邮件。我使用javax.mail来实现这一点。请在下面找到我代码的一部分 InternetAddress[] myToList = InternetAddress.parse("gopi.mani@xyz.com,Maimsa.SF@xyz.com"); InternetAddress[] myBccList = InternetAddress.parse("Usha.B@xyz.com"); InternetAddress[] myCcList = Int

我正在尝试用收件人、抄送和密件抄送发送邮件。我使用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收件人太多

试试这个

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);
InternetAddress[]toAddress=新的InternetAddress[to.length];
//获取ToAddress数组的步骤
for(int i=0;i

如果您需要使用CC或BCC,则使用not us.setRecipients

设置属性了吗?“452 4.5.3收件人太多”使我相信SMTP服务器拒绝了您的电子邮件,而不是Java问题。你有没有试过只使用一个收件人来查看是否继续出现此错误?是的,我设置了如下属性,properties props=new properties();props.put(“mail.smtp.auth”、“false”);props.put(“mail.smtp.starttls.enable”、“true”);props.put(“mail.smtp.host”,主机名);props.put(“mail.smtp.port”,port);你好,史蒂文,如果我单独使用“message.setRecipients(message.RecipientType.TO,myToList)”,并删除“密件抄送”和“抄送”代码行。我的代码运行良好。请确认这是Java问题还是SMTP问题server@user2928305:该错误消息直接来自SMTP服务器。addRecipient方法仅允许“message”和Address作为其参数,而不允许Address[](数组)。只有addRecipients允许使用数组。我尝试了这两种方法,但仍然失败。是的,即使如此,异常仍然存在。您的代码似乎正确,问题可能是SMTP服务器。您发布的代码对我有效
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]);
        }