//props.put("mail.smtp.auth","true");
// props.put("mail.smtp.user", "jb_china2004");
//props.put("mail.smtp.password", "不能说");
把注释去掉,写一个授权类:
public class MyAuthenticator extends javax.mail.Authenticator
{
private String m_username = null;
private String m_userpass = null;public void setUsername(String username)
{
m_username = username;
}public void setUserpass(String userpass)
{
m_userpass = userpass;
}public MyAuthenticator (String username, String userpass)
{
super(); setUsername(username);
setUserpass(userpass);}
public PasswordAuthentication getPasswordAuthentication()
{ return new PasswordAuthentication(m_username,m_userpass);
}
}
//***********************
sendMailSession = Session.getInstance(props, new MyAuthenticator(username,password));
// props.put("mail.smtp.user", "jb_china2004");
//props.put("mail.smtp.password", "不能说");
把注释去掉,写一个授权类:
public class MyAuthenticator extends javax.mail.Authenticator
{
private String m_username = null;
private String m_userpass = null;public void setUsername(String username)
{
m_username = username;
}public void setUserpass(String userpass)
{
m_userpass = userpass;
}public MyAuthenticator (String username, String userpass)
{
super(); setUsername(username);
setUserpass(userpass);}
public PasswordAuthentication getPasswordAuthentication()
{ return new PasswordAuthentication(m_username,m_userpass);
}
}
//***********************
sendMailSession = Session.getInstance(props, new MyAuthenticator(username,password));
解决方案 »
- 我们爱分享---Java开发环境的Eclipse快捷键大全,网上很多,我又总结了一下
- 服务器压力问题!!!!
- axis2共享变量的问题
- IE访问问题:部分文字和图片看不了
- jbuilder2006 webservice的问题
- 谁能帮我解决hibernate的问题
- Axis中Read Timed out 问题,急!
- 谁有Struts的教程
- 关于包引用的一点问题
- 怎样发布项目,测试tomcat是否配置成功,,
- 启动WEBLOGIC是否一定要连接到INTERNET上?我单机调试程序总是无法启动WEBLOGIC,HELP!
- 本人用eclips的tomcat插件启动tomacat出错,高手帮忙看一下!!
import javax.mail.PasswordAuthentication;public class MyAuthenticator extends Authenticator
{
private String m_username = null;
private String m_userpass = null;
public void setUsername(String username)
{
m_username = username;
}
public void setUserpass(String userpass)
{
m_userpass = userpass;
}
public MyAuthenticator (String username, String userpass)
{
super();
setUsername(username);
setUserpass(userpass);
}
public PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(m_username, m_userpass);
}
}
import javax.mail.*;
import javax.activation.*;
import java.util.*;
import javax.mail.internet.*;public class SendMail
{
public static void main(String[] args)
{
try
{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.smtp.user", "jb_china2004");
props.put("mail.smtp.password", "jbChina2004");
//props.put("mail.smtp.auth","true");
//sendMailSession = Session.getInstance(props, null);
sendMailSession = Session.getInstance(props, new MyAuthenticator("jb_china2004","jbChina2004"));
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress("[email protected]"));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
newMessage.setSubject("测试发信");
newMessage.setSentDate(new Date());
newMessage.setText("测试发信成功,欢喜之中");
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
System.out.println ("发送成功");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}还是不好用,
提示
javax.mail.MessagingException:553 you are not authorized to send mail as<mail from <[email protected]>>,authentication is required密码也告诉你啦, 麻烦你帮忙看一下呸,我没做过邮件发送, 都好几天没弄出来啦!
import javax.activation.*;
import java.util.*;
import javax.mail.internet.*;public class SendMail
{
public static void main(String[] args)
{
try
{
Properties props = new Properties();
Session sendMailSession;
Store store;
Transport transport;
SmtpAuthenticator sa=new SmtpAuthenticator("jb_china2004","jbChina2004");
props.put("mail.smtp.host", "smtp.163.com");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.auth","true");
// props.put("mail.smtp.user", "jb_china2004");
// props.put("mail.smtp.password", "jbChina2004");
// sendMailSession = Session.getInstance(props, null);
sendMailSession = Session.getInstance(props, sa);
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress("[email protected]"));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
newMessage.setSubject("测试发信");
newMessage.setSentDate(new Date());
newMessage.setText("测试发信成功,欢喜之中");
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
System.out.println ("发送成功");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class SmtpAuthenticator extends Authenticator
{ String username;
String password; public SmtpAuthenticator(String s, String s1)
{
username = s;
password = s1;
} protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(username, password);
}
}