我想问一下,那个SmtpAuthenticator 是在哪个包里的啊? 还有我send为啥老是不成功, You are not authorized to send mail as <MAIL FROM:<[email protected]>>, authentication is required[04-5-9 23:28:57:469 CST] 1d24866 SystemOut O javax.mail.MessagingException: 553 You are not authorized to send mail as <MAIL FROM:<[email protected]>>, authentication is required 可是我已经用我自己在163上注册的账号s m.setAccount("shadow.net_1984","*****"); 请高手指教
props.put("mail.smtp.auth", "true");别的地方看来的,自己试试看吧
import javax.mail.internet.*;
import java.io.*;
import javax.activation.*;
import java.util.*;public class SMTPVerify extends Authenticator
{
protected PasswordAuthentication getPasswordAuthentication()
{
return(new PasswordAuthentication("bromon","******"));
}
public static void main(String args[])
{
try
{
String to="[email protected]";
String from="[email protected]";
String subject="你好";
Properties props=System.getProperties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host","smtp.eyou.com");
SmtpAuthenticator sa=new SmtpAuthenticator();
Session sess=Session.getInstance(props,sa);
sess.setDebug(true);
Message msg=new MimeMessage(sess);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO,InternetAddress.parse(to,false));
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText("你好");
Transport.send(msg);
}catch(Exception e)
{
System.out.println(e);
}
}
}
//实例SMTP认证对象
SmtpAuthenticator sa=new SmtpAuthenticator(user,pass);
//设置SMTP服务器
props.put("mail.smtp.host", smtp);
//设置需要身份认证为真
props.put("mail.smtp.auth","true");
//获得一个会话
Session session=Session.getInstance(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.send(msg);
还有我send为啥老是不成功,
You are not authorized to send mail as <MAIL FROM:<[email protected]>>, authentication is required[04-5-9 23:28:57:469 CST] 1d24866 SystemOut O javax.mail.MessagingException: 553 You are not authorized to send mail as <MAIL FROM:<[email protected]>>, authentication is required
可是我已经用我自己在163上注册的账号s
m.setAccount("shadow.net_1984","*****");
请高手指教