0

Same piece of code works successfully in Gmail for replying messages, but in yahoo, I'm getting error.

Here is the code I've tried

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 ....");

The error I'm getting:

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)

Please point me to the right direction ,what I'm doing wrong.

Mahbub shaun
  • 23
  • 1
  • 8

1 Answers1

0

The Yahoo mail server doesn't like one of your recipients of the reply message. Try enabling JavaMail debug output and you might get more information about what's wrong.

Note also that you're creating the replyMessage by using the MimeMessage constructor, then throwing that value away and assigning it to the return value of the reply method. You can get rid of the call to the constructor, which is doing nothing.

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40