初学者; javamail编写的smtp发送邮件小程序,向163发送邮件失败 求救
我用此小程序发送邮件到sohu是可以发送成功的,但是向163发送时却遇到这样的错误提示:
553 Requested action not taken: Local user only,smtp1,wKjRC7Dr+AGpORxGgCA5FA==.12289S2 1176254
请问是什么原因?
如果是因为身份验证的原因的话,我已经加入身份验证的部分了
源程序如下:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import java.io.*;
public class SimpleSmtpClient
{
String smtpServer;
String to;
String from;
String subject;
String body;
String username;
String password;
public SimpleSmtpClient(){
setup();
log( "Constructor complete ");
}
private void setup()
{
smtpServer= "smtp.163.com ";
to= "50971231@163.com ";
from= "50971231@sohu.com ";
subject= "Unleased book example ";
body= "This is a test to see if we can send a messge/double test ";
username= "50971231 ";
password= "******* ";
log( "setup completed ");
}
private void send()
{
try{
log( "Sending a message to "+to);
Properties props=System.getProperties();
props.put( "mail.smtp.host ",smtpServer);
props.put( "mail.smtp.user ", "50971231 ");
props.put( "mail.debug ", "true ");
StupidAuthenticator sa=new StupidAuthenticator();
Session session =Session.getDefaultInstance(props,sa);
Message msg=new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to,false));
msg.setSubject(subject);
msg.setText(body);
msg.setSentDate(new Date());
Transport transport =session.getTransport( "smtp ");
transport.connect(smtpServer,username,password);
transport.sendMessage(msg,msg.getAllRecipients());
transport.close();
System.out.println( "Message was sent ");
}catch(Exception e)
{
log( "Error sending message "+e);
}
}
private void log(String s)
{
System.out.println(s);
}
public static void main( String args[])
{
SimpleSmtpClient sc=new SimpleSmtpClient();
sc.send();
System.out.println( "SimleSmtpClient is done ");
}
}
------解决方案--------------------应该是本地用户才能发送吧
------解决方案--------------------smtpServer= "smtp.163.com ";
to= "50971231@163.com ";
props.put( "mail.smtp.host ",smtpServer);
props.put( "mail.smtp.user ", "50971231 ");