当前位置: 技术问答>java相关
用JavaMail发信(Smtp)怎么加身份验证????
来源: 互联网 发布时间:2015-07-21
本文导语: 请给个具体语句,谢谢!!! | Properties props = System.getProperties(); props.put("mail.smtp.auth","true"); | import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; import com.sun.mail.sm...
请给个具体语句,谢谢!!!
|
Properties props = System.getProperties();
props.put("mail.smtp.auth","true");
props.put("mail.smtp.auth","true");
|
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
import com.sun.mail.smtp.*;
import java.util.*;
public class mymail extends Authenticator {
String userName,password;
public mymail(String user,String pass) {
super();
userName=new String(user);
password=new String(pass);
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(userName,password);
}
public static void main(String[] args){
try{
Properties props=new Properties();
props.put("mail.host","smtp.163.com");
props.put("mail.transport.protocol","smtp");
//props.put("mail.transport.port","25");
props.put("mail.smtp.auth","true"); //这行一定要有
继承Authenticator类!
import javax.mail.internet.*;
import javax.activation.*;
import com.sun.mail.smtp.*;
import java.util.*;
public class mymail extends Authenticator {
String userName,password;
public mymail(String user,String pass) {
super();
userName=new String(user);
password=new String(pass);
}
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication(userName,password);
}
public static void main(String[] args){
try{
Properties props=new Properties();
props.put("mail.host","smtp.163.com");
props.put("mail.transport.protocol","smtp");
//props.put("mail.transport.port","25");
props.put("mail.smtp.auth","true"); //这行一定要有
继承Authenticator类!