求救: javamail 程序只能在同一个域内发送!!
比如:
a@domain1.com 可以发邮件给所有 @domain1.com的用户,但如果是发邮件
给*@domain2.com或者其他域中的用户的时候,就会报错:
javax.mail.SendFailedException: Sending failed;
nested exception is: javax.mail.SendFailedException: Invalid Addresses;
nested exception is: javax.mail.SendFailedException: 550 <*@domain2.com>: Invalid User
代码如下:
//the mail client
public MailClient(String user, String passwe String host) {
PasswordAuthentication authentication = new PasswordAuthentication(user, passwd);
Properties props = new Properties();
props.put("mail.user", user);
props.put("mail.host", host);
props.put("mail.store.protocol", "pop3");
props.put("mail.transport.protocol", "smtp");
session = Session.getInstance(props, this);
}
public PasswordAuthentication getPasswordAuthentication() {
return authentication;
}
//send message
public void sendMessage(
String to, String subject, String content) throws
MessagingException {
MimeMessage msg = new MimeMessage(session);
msg.addRecipients(Message.RecipientType.TO, to);
msg.setSubject(subject);
msg.setText(content);
Transport.send(msg);
}