├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── yuyh │ │ └── simplemail │ │ ├── LoginActivity.java │ │ ├── MailApp.java │ │ └── MainActivity.java │ └── res │ ├── layout │ ├── activity_login.xml │ └── activity_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── libs │ ├── activation.jar │ ├── additionnal.jar │ └── mail.jar ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── yuyh │ │ └── library │ │ └── simplemail │ │ ├── MailHelper.java │ │ ├── bean │ │ ├── Attachment.java │ │ ├── Email.java │ │ ├── LoginInfo.java │ │ ├── MailDraft.java │ │ ├── ReceiverMailInfo.java │ │ ├── SendMailInfo.java │ │ └── User.java │ │ ├── constant │ │ └── Constants.java │ │ └── utils │ │ ├── MailAuthenticator.java │ │ └── StringUtils.java │ └── res │ └── values │ └── strings.xml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | SimpleMail -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 24 | 25 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SimpleMail 2 | ### 一个基于POP3和SMTP协议的邮件客户端。 3 | 4 | 5 | ## 登录 6 | ```java 7 | String address = "smuyyh@126.com"; 8 | String pwd = "xxxxxxxxxx"; 9 | String host = "smtp." + address.substring(address.lastIndexOf("@") + 1); 10 | 11 | final LoginInfo info = new LoginInfo(); 12 | info.mailServerHost = host; 13 | info.mailServerPort = "25"; 14 | info.userName = address; 15 | info.password = pwd; 16 | info.validate = true; 17 | new Thread(new Runnable() { 18 | @Override 19 | public void run() { 20 | Session session = MailHelper.getInstance(MainActivity.this).login(info); 21 | if(session != null){ 22 | // 登录成功 23 | } 24 | } 25 | }).start(); 26 | ``` 27 | 28 | ## 收件箱 29 | ```java 30 | try { 31 | List list = MailHelper.getInstance(MainActivity.this).getAllMail(Constants.MailFolder.INBOX, info, session); 32 | Log.i("TAG", list.size()+""); 33 | } catch (MessagingException e) { 34 | e.printStackTrace(); 35 | } 36 | 37 | ``` 38 | 39 | ## 发送邮件 40 | ```java 41 | SendMailInfo info = new SendMailInfo(); 42 | info.fromAddress = address; 43 | info.subject = "测试邮件"; 44 | info.content = "测试邮件 内容"; 45 | info.receivers = new String[]{"352091626@qq.com"}; 46 | MailHelper.getInstance(MainActivity.this).sendMail(info, session); 47 | ``` -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.3" 6 | 7 | defaultConfig { 8 | applicationId "com.yuyh.simplemail" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | compile project(':library') 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | compile 'com.android.support:design:23.4.0' 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in D:\AndroidDev\sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/com/yuyh/simplemail/LoginActivity.java: -------------------------------------------------------------------------------- 1 | package com.yuyh.simplemail; 2 | 3 | import android.content.Intent; 4 | import android.os.AsyncTask; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.view.View; 9 | import android.widget.Button; 10 | import android.widget.EditText; 11 | import android.widget.ProgressBar; 12 | import android.widget.Toast; 13 | 14 | import com.yuyh.library.simplemail.MailHelper; 15 | import com.yuyh.library.simplemail.bean.LoginInfo; 16 | 17 | import javax.mail.Session; 18 | 19 | /** 20 | * A login screen that offers login via email/password. 21 | */ 22 | public class LoginActivity extends AppCompatActivity { 23 | 24 | private Button btnLogin; 25 | 26 | private EditText etMail; 27 | private EditText etPwd; 28 | 29 | private ProgressBar progressBar; 30 | 31 | @Override 32 | protected void onCreate(@Nullable Bundle savedInstanceState) { 33 | super.onCreate(savedInstanceState); 34 | setContentView(R.layout.activity_login); 35 | 36 | progressBar = (ProgressBar) findViewById(R.id.login_progress); 37 | 38 | etMail = (EditText) findViewById(R.id.email); 39 | etPwd = (EditText) findViewById(R.id.password); 40 | 41 | btnLogin = (Button) findViewById(R.id.email_sign_in_button); 42 | } 43 | 44 | public void login(View view) { 45 | String mail = etMail.getText().toString().trim(); 46 | String pwd = etPwd.getText().toString().trim(); 47 | 48 | new LoginTask().execute(mail, pwd); 49 | } 50 | 51 | class LoginTask extends AsyncTask { 52 | 53 | @Override 54 | protected void onPreExecute() { 55 | super.onPreExecute(); 56 | progressBar.setVisibility(View.VISIBLE); 57 | } 58 | 59 | @Override 60 | protected Boolean doInBackground(String... params) { 61 | String address = params[0]; 62 | String pwd = params[1]; 63 | String host = "smtp." + address.substring(address.lastIndexOf("@") + 1); 64 | 65 | final LoginInfo info = new LoginInfo(); 66 | info.mailServerHost = host; 67 | info.mailServerPort = "25"; 68 | info.userName = address; 69 | info.password = pwd; 70 | info.validate = true; 71 | Session session = MailHelper.getInstance(LoginActivity.this).login(info); 72 | if (session != null) { 73 | MailApp.session = session; 74 | MailApp.info = info; 75 | return true; 76 | } 77 | return false; 78 | } 79 | 80 | @Override 81 | protected void onPostExecute(Boolean result) { 82 | if (result) { 83 | Toast.makeText(LoginActivity.this, "登录成功", Toast.LENGTH_SHORT).show(); 84 | startActivity(new Intent(LoginActivity.this, MainActivity.class)); 85 | } else { 86 | Toast.makeText(LoginActivity.this, "登录失败", Toast.LENGTH_SHORT).show(); 87 | } 88 | progressBar.setVisibility(View.GONE); 89 | } 90 | } 91 | } 92 | 93 | -------------------------------------------------------------------------------- /app/src/main/java/com/yuyh/simplemail/MailApp.java: -------------------------------------------------------------------------------- 1 | package com.yuyh.simplemail; 2 | 3 | import android.app.Application; 4 | 5 | import com.yuyh.library.simplemail.bean.LoginInfo; 6 | 7 | import javax.mail.Session; 8 | 9 | /** 10 | * @author yuyh. 11 | * @date 2016/8/1. 12 | */ 13 | public class MailApp extends Application { 14 | 15 | public static Session session; 16 | public static LoginInfo info; 17 | 18 | @Override 19 | public void onCreate() { 20 | super.onCreate(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/yuyh/simplemail/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.yuyh.simplemail; 2 | 3 | import android.os.Bundle; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.util.Log; 6 | 7 | import com.yuyh.library.simplemail.MailHelper; 8 | import com.yuyh.library.simplemail.bean.ReceiverMailInfo; 9 | import com.yuyh.library.simplemail.bean.SendMailInfo; 10 | import com.yuyh.library.simplemail.constant.Constants; 11 | 12 | import java.util.List; 13 | 14 | import javax.mail.MessagingException; 15 | import javax.mail.Session; 16 | 17 | public class MainActivity extends AppCompatActivity { 18 | 19 | private MailHelper helper; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | setContentView(R.layout.activity_main); 25 | 26 | helper = MailHelper.getInstance(MainActivity.this); 27 | 28 | new Thread(new Runnable() { 29 | @Override 30 | public void run() { 31 | Session session = MailApp.session; 32 | if(session != null){ 33 | try { 34 | List list = helper.getAllMail(Constants.MailFolder.INBOX, MailApp.info, session); 35 | Log.i("TAG", list.size()+""); 36 | 37 | SendMailInfo info = new SendMailInfo(); 38 | info.fromAddress = MailApp.info.userName; 39 | info.subject = "测试邮件"; 40 | info.content = "测试邮件 内容"; 41 | info.receivers = new String[]{"352091626@qq.com"}; 42 | helper.sendMail(info, session); 43 | } catch (MessagingException e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | } 48 | }).start(); 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 12 | 13 | 14 | 21 | 22 | 26 | 27 | 32 | 33 | 36 | 37 | 46 | 47 | 48 | 49 | 52 | 53 | 65 | 66 | 67 | 68 |