前景提要
HDC调试需求开发(15万预算),能者速来!>>> 我用javamail向.@sina.cn 或者 @qq.com发送邮件失败。只能给本公司邮件服务器中的邮箱发送邮件。请问这是为什么? 异常信息: javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <yangbo343567562@sina.cn>: Relay access denied ; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <lovesmellysmelly@qq.com>: Relay access denied ; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <lovesmellysmelly@qq.com>: Relay access denied at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1196) at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:584) at javax.mail.Transport.send0(Transport.java:169) at javax.mail.Transport.send(Transport.java:98) at test.SendMailTest.sendMail(SendMailTest.java:70) at test.SendMailTest.main(SendMailTest.java:117) Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <yangbo343567562@sina.cn>: Relay access denied ; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <lovesmellysmelly@qq.com>: Relay access denied 发送邮件失败 at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1094) ... 5 more Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 <lovesmellysmelly@qq.com>: Relay access denied ... 6 more public boolean sendMail() { Properties propers = new Properties(); propers.put("mail.smtp.host", host); propers.put("mail.smtp.auth", "true"); // propers.setProperty("mail.smtp.socketFactory.fallback", "false"); // propers.setProperty("mail.smtp.port", "25"); // propers.setProperty("mail.smtp.socketFactory.port", "25"); Session session = Session.getDefaultInstance(propers,new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); Message message = new MimeMessage(session); try { message.setText(content); message.setFrom(new InternetAddress(username, parName)); message.setSubject(subject); Address[] addressesTo = new InternetAddress[to.length]; for (int i = 0; i < to.length; i++) { addressesTo[i] = new InternetAddress(to[i]); } message.addRecipients(Message.RecipientType.TO, addressesTo); // InternetAddress[] addressCc = new InternetAddress[cc.length]; // for (int i = 0; i < cc.length; i++) { // addressCc[i] = new InternetAddress(cc[i]); // } // message.addRecipients(Message.RecipientType.CC, addressCc); message.setContent(content,"text/html;charset=GBK"); message.saveChanges(); Transport.send(message); System.out.println("send mail ok!"); } catch (Exception e) { e.printStackTrace(); return false; } return true; } String host ="smtp.gdyilian.com"; String username = "payreporter@payeco.com"; String password = "4489a6"; // private String name = "yangbo"; // private String value = "343567562"; // private String to[] = {"yang.bo@payeco.com"}; private String to[] = { "yangbo343567562@sina.cn", "lovesmellysmelly@qq.com", "yang.bo@payeco.com" };// 收件人 private String cc[] = {"lovesmellysmelly@qq.com" }; // private String cc[] = { "yangbo343567562@sina.cn", // "lovesmellysmelly@qq.com", "yang.bo@payeco.com" };// 抄送人; private String from = "yangbo343567562@sina.cn"; private String subject = "YANGBO"; private String content = "this is the Test javamail"; private String parName = "system";