无法使用JAVA MAIL API在Yahoo中回复邮件

问题描述 投票:0回答:1

同一段代码在Gmail中可以成功地用于回复邮件,但是在yahoo中,我遇到了错误。

这是我尝试过的代码

Message[] messages2 = folder.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
Message msg =  messages2[i];
 System.out.println("\n 1st ===> setup Mail Server Properties..");
                                        mailServerProperties = System.getProperties();
                                        mailServerProperties.put("mail.smtp.port", "587");
                                        mailServerProperties.put("mail.smtp.auth", "true");
                                        mailServerProperties.put("mail.smtp.starttls.enable", "true");
System.out.println("Mail Server Properties have been setup successfully..");
                                        getMailSession = Session.getDefaultInstance(mailServerProperties, null);

                                        Message replyMessage = new MimeMessage(getMailSession);
                                          replyMessage = (MimeMessage) msg.reply(false);
                                          replyMessage.setFrom(new InternetAddress(to));
                                          replyMessage.setText("Thanks");
                                          replyMessage.setReplyTo(msg.getReplyTo());

                                          // Send the message by authenticating the SMTP server
                                          // Create a Transport instance and call the sendMessage
                                          Transport t = session.getTransport("smtp");
                                          try {
                                     //connect to the smpt server using transport instance
                                     //change the user and password accordingly 
                                         t.connect("smtp.mail.yahoo.com",table_user, table_pass);
                                         t.sendMessage(replyMessage,
                                                replyMessage.getAllRecipients());
                                          } finally {
                                             t.close();
                                          }
                                          System.out.println("message replied successfully ....");

我得到的错误:

com.sun.mail.smtp.SMTPSendFailedException: 550 Request failed; Mailbox unavailable

at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1829)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1634)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:889)
at mail$8.doInBackground(mail.java:1114)
at mail$8.doInBackground(mail.java:1)
at javax.swing.SwingWorker$1.call(SwingWorker.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at javax.swing.SwingWorker.run(SwingWorker.java:334)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

[请指出正确的方向,这是我做错了。

smtp javamail yahoo-mail
1个回答
0
投票

Yahoo邮件服务器不喜欢您的回复邮件收件人之一。尝试启用JavaMail debug output,您可能会得到更多有关错误的信息。

还请注意,您正在使用MimeMessage构造函数创建ReplyMessage,然后将该值扔掉并将其分配给Reply方法的返回值。您可以摆脱对构造函数的调用,该调用不执行任何操作。

© www.soinside.com 2019 - 2024. All rights reserved.