本帖最后由 韩爽 于 2012-7-28 18:08 编辑
- package cn.itcast.xxx;
- import java.io.BufferedReader;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.util.Date;
- import java.util.Properties;
- import sun.misc.resources.*;
- import javax.mail.Address;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- import javax.xml.transform.Templates;
- import sun.corba.*;
- import javax.mail.internet.*;
- public class MainClass {
- /**
- * @param args
- * @throws Exception
- */
- public static void main(String[] args) throws Exception {
- // TODO Auto-generated method stub
- Properties p = new Properties();
- p.setProperty("mail.transport.protocol", "smtp");//KET位置是使用协议
- p.setProperty("mail.smtp.auth","true");
- Session se= Session.getInstance(p);//
- se.setDebug(true);
- Transport t = se.getTransport();//不可以直接new
- Message meg =new MimeMessage(se);
- meg.setSubject("你好");
- meg.setFrom(InternetAddress.parse("<549444333@qq.com>")[0]);
- meg.setText("最近在黑马学习什么?");
-
-
- InputStream ips = MainClass.class.getResourceAsStream("pass.dat");
- BufferedReader br =new BufferedReader(new InputStreamReader(ips));
- String pass=br .readLine();
- br.close();
-
- t.connect("smtp.qq.com","549444333@qq.com","pass");
- t.sendMessage(meg, new Address[]{new InternetAddress("729034188@qq.com")});
- }
- }
复制代码 错误提示如下:- Exception in thread "main" javax.mail.AuthenticationFailedException: 535 Authentication failed
- at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:648)
- at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
- at javax.mail.Service.connect(Service.java:291)
- at javax.mail.Service.connect(Service.java:172)
- at cn.itcast.xxx.MainClass.main(MainClass.java:47)
复制代码 求各位帮帮忙阿
QQ邮箱支持的那个我都设置了。
|