当前位置: 技术问答>java相关
急!用Java Mail发信总是失败
来源: 互联网 发布时间:2015-10-06
本文导语: 用Java Mail发信总是失败,提示: javax.mail.SendFailedException: 550 5.7.1 Unable to relay for aaa@163.com at javax.mail.Transport.send0(Transport.java:219) at javax.mail.Transport.send0(Transport.java:81) 邮件地址绝对有效,请教高手,怎么回事? ...
用Java Mail发信总是失败,提示:
javax.mail.SendFailedException: 550 5.7.1 Unable to relay for aaa@163.com
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send0(Transport.java:81)
邮件地址绝对有效,请教高手,怎么回事?
-----------------------------------
源代码:
MimeMessage mimeMsg = null;
Session session = null;
try {
Properties props = System.getProperties();
props.put("mail.smtp.host", "localhost");
session = Session.getDefaultInstance(props,null);
mimeMsg = new MimeMessage( session );
mimeMsg.setFrom(new InternetAddress("aaa@163.com"));
mimeMsg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( "bbb@163.com" ) );
mimeMsg.setSubject("test");
mimeMsg.setText("test mail" );
mimeMsg.setSentDate(new Date());
Transport.send( mimeMsg );
}
catch (Exception e) {
e.printStackTrace();
}
javax.mail.SendFailedException: 550 5.7.1 Unable to relay for aaa@163.com
at javax.mail.Transport.send0(Transport.java:219)
at javax.mail.Transport.send0(Transport.java:81)
邮件地址绝对有效,请教高手,怎么回事?
-----------------------------------
源代码:
MimeMessage mimeMsg = null;
Session session = null;
try {
Properties props = System.getProperties();
props.put("mail.smtp.host", "localhost");
session = Session.getDefaultInstance(props,null);
mimeMsg = new MimeMessage( session );
mimeMsg.setFrom(new InternetAddress("aaa@163.com"));
mimeMsg.setRecipients( Message.RecipientType.TO, InternetAddress.parse( "bbb@163.com" ) );
mimeMsg.setSubject("test");
mimeMsg.setText("test mail" );
mimeMsg.setSentDate(new Date());
Transport.send( mimeMsg );
}
catch (Exception e) {
e.printStackTrace();
}
|
如果使用163的信箱发信的话,mail.smtp.host的地址应该是smtp.163.com吧
我写过一个可以用的,你看看
try{
Properties Props=new Properties();
Props.put("mail.smtp.host","192.168.1.5");
Session mailConnection=Session.getInstance(Props,null);
Address fromAddress=new InternetAddress(""myname"");//this mail address must be true;
List sendAddr = new ArrayList();
for (int i = 0; i 0)
sendAddr.add(argmailContent.getsendTo().get(i));
}
Address[] toAddress = new Address[sendAddr.size()];
for (int i = 0; i
我写过一个可以用的,你看看
try{
Properties Props=new Properties();
Props.put("mail.smtp.host","192.168.1.5");
Session mailConnection=Session.getInstance(Props,null);
Address fromAddress=new InternetAddress(""myname"");//this mail address must be true;
List sendAddr = new ArrayList();
for (int i = 0; i 0)
sendAddr.add(argmailContent.getsendTo().get(i));
}
Address[] toAddress = new Address[sendAddr.size()];
for (int i = 0; i