├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ └── activity_main.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── zhengsr
│ │ │ └── emaildemo
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zhengsr
│ │ │ └── emaildemo
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zhengsr
│ │ └── emaildemo
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── zemaillib
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── android
│ │ │ └── zemaillib
│ │ │ ├── callback
│ │ │ └── IEmailSendListener.java
│ │ │ ├── MailAuthenticator.java
│ │ │ ├── bean
│ │ │ └── ZEmailBean.java
│ │ │ ├── ZMailManager.java
│ │ │ └── ZemailRequest.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── android
│ │ │ └── zemaillib
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── android
│ │ └── zemaillib
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── misc.xml
└── codeStyles
│ └── Project.xml
├── gradle.properties
├── .gitignore
├── README.md
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/zemaillib/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':zemaillib'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | EmailDemo
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/zemaillib/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ZemailLib
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/zemaillib/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LillteZheng/ZMail/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Sep 02 15:02:11 CST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/zemaillib/src/main/java/com/android/zemaillib/callback/IEmailSendListener.java:
--------------------------------------------------------------------------------
1 | package com.android.zemaillib.callback;
2 |
3 | /**
4 | * Created by zhengshaorui on 2018/6/12.
5 | */
6 |
7 | public interface IEmailSendListener {
8 | void sendStart();
9 | void sendFailed(String errorMsg);
10 | void sendSuccess();
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zhengsr/emaildemo/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zhengsr.emaildemo;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/zemaillib/src/test/java/com/android/zemaillib/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.android.zemaillib;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/zemaillib/src/main/java/com/android/zemaillib/MailAuthenticator.java:
--------------------------------------------------------------------------------
1 | package com.android.zemaillib;
2 |
3 |
4 | import javax.mail.PasswordAuthentication;
5 |
6 | /**
7 | * Created by zhengshaorui on 2018/6/11.
8 | */
9 |
10 | public class MailAuthenticator extends javax.mail.Authenticator {
11 | private String addr;
12 | private String password;
13 |
14 | public MailAuthenticator(String addr, String password) {
15 | this.addr = addr;
16 | this.password = password;
17 | }
18 |
19 | @Override
20 | protected PasswordAuthentication getPasswordAuthentication() {
21 | return new PasswordAuthentication(addr,password);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/zemaillib/src/main/java/com/android/zemaillib/bean/ZEmailBean.java:
--------------------------------------------------------------------------------
1 | package com.android.zemaillib.bean;
2 |
3 |
4 | import com.android.zemaillib.callback.IEmailSendListener;
5 |
6 | /**
7 | * Created by zhengshaorui
8 | * Time on 2018/12/22
9 | */
10 |
11 | public class ZEmailBean {
12 | public String fromAddr;
13 | public String nickName;
14 | public String password;
15 | public String subject;
16 | public String content;
17 | public String[] toAddrs;
18 | public String[] filePaths;
19 | public String url;
20 | public String host = null;
21 | public String port = null;
22 | public boolean isSSLverify = true;
23 | public IEmailSendListener listener;
24 | }
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/zemaillib/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zhengsr/emaildemo/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zhengsr.emaildemo;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.zhengsr.emaildemo", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/zemaillib/src/androidTest/java/com/android/zemaillib/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.android.zemaillib;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.android.zemaillib.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/zemaillib/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | group='com.github.LillteZheng'
4 | android {
5 | compileSdkVersion 28
6 |
7 |
8 |
9 | defaultConfig {
10 | minSdkVersion 19
11 | targetSdkVersion 28
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 |
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 |
26 | }
27 |
28 | dependencies {
29 | implementation fileTree(dir: 'libs', include: ['*.jar'])
30 |
31 | implementation 'com.android.support:appcompat-v7:28.0.0'
32 | testImplementation 'junit:junit:4.12'
33 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
34 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
35 | compile 'com.sun.mail:android-mail:1.6.2'
36 | compile 'com.sun.mail:android-activation:1.6.2'
37 | }
38 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Files for the ART/Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 | out/
15 |
16 | # Gradle files
17 | .gradle/
18 | build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # IntelliJ
36 | *.iml
37 | .idea/workspace.xml
38 | .idea/tasks.xml
39 | .idea/gradle.xml
40 | .idea/assetWizardSettings.xml
41 | .idea/dictionaries
42 | .idea/libraries
43 | .idea/caches
44 |
45 | # Keystore files
46 | # Uncomment the following line if you do not want to check your keystore files in.
47 | #*.jks
48 |
49 | # External native build folder generated in Android Studio 2.2 and later
50 | .externalNativeBuild
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
66 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.zhengsr.emaildemo"
7 | minSdkVersion 21
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | packagingOptions {
20 | pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
21 | }
22 | }
23 |
24 | repositories {
25 | jcenter()
26 | maven {
27 | url "https://maven.java.net/content/groups/public/"
28 | }
29 | }
30 | dependencies {
31 | implementation fileTree(include: ['*.jar'], dir: 'libs')
32 | implementation 'com.android.support:appcompat-v7:28.0.0'
33 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
34 | testImplementation 'junit:junit:4.12'
35 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
36 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
37 | compile 'com.sun.mail:android-mail:1.6.2'
38 | compile 'com.sun.mail:android-activation:1.6.2'
39 | implementation project(':zemaillib')
40 | }
41 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Zmail
2 |
3 |
4 | 在一般的 apk 中,我们都会设置一个让用户提意见的功能,常见的做法,就是申请一个通用邮箱,让内容发送过来就好了。
5 |
6 | 而这里的邮箱发送,属于第三方邮件发送,即本来你申请的是 163 的,然后却用 QQ 邮箱去登录,那肯定是不行的,所以需要申请授权码,申请之后,就用账号加授权码发送即可。
7 |
8 | **注意,如果是公司邮箱,记得去你们的邮箱配置服务器中,查看SMTP服务器,端口和是否开启SSL,每个公司都不一样,目前还未遇到不能用的情况**
9 |
10 | 所以,这里添加一个 ZMailManager 的工具类。
11 |
12 | ## 关联
13 | ```
14 | allprojects {
15 | repositories {
16 | ...
17 | maven { url 'https://jitpack.io' }
18 | }
19 | }
20 | ```
21 | ```
22 | implementation 'com.github.LillteZheng:ZMail:v1.1'
23 | ```
24 | ZMailManager 代码非常简单:
25 | ```
26 | /**
27 | * fromAddr -- 发送人邮箱,不填报错
28 | * nickName -- 发送人的昵称,不写则默认为邮箱名
29 | * password -- 授权码,不填报错,gmail 记得允许权限低的应用可以访问的权限
30 | * host -- 配置 host 服务地址,默认根据发件人的邮箱来,比如 xx@qq.com ,则 host 为 smtp.qq.com
31 | * isSSLvertify -- 是否开启SSL验证,默认开启,开启是端口为465,不开启则为25,建议开启,很多邮箱都需要验证 SSL的
32 | * port -- 根据isSSLvertify,开启是端口为465,不开启则为25,也支持自定义
33 | * subject -- 邮件主题
34 | * content -- 邮件内容
35 | * file -- 支持 url 和 本地文件,可多个
36 | * toAddrs -- 收件人,多个多个,必填,不填报错
37 | */
38 | ZMailManager
39 | .fromAddr(SEND_EMAIL)
40 | .nickName("会散步的鱼")
41 | .password(PASSWORD)
42 | //.host("smtp.163.com")
43 | //.isSSLvertify(false)
44 | //.port(25)
45 | .subject("测试邮件")
46 | .content("这是一封测试邮件!")
47 | .file(imageUrl)
48 | // .file(new String[]{imagePath})
49 | .toAddrs(new String[]{TO_EMAIL})
50 | .listener(this)
51 | .send();
52 | ```
53 |
54 | Gmail 比较蛋疼,申请了授权码之后,需要允许应用权限低的才能访问,但还是会被阻止,需要手动去确实是自己的登录行为。
55 | 错误提示有,自己去研究了。。。
56 |
57 | 混淆看这里,感谢 @xingstarx :
58 | ```
59 | -keep class javax.mail.** {*;}
60 | -keep class javax.activation.** {*;}
61 | -keep class com.android.zemaillib.** {*;}
62 | -keep class com.sun.mail.** {*;}
63 | -keep class com.sun.activation.registries.** {*;}
64 | -dontwarn java.awt.**
65 | -dontwarn javax.activation.**
66 | ```
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zhengsr/emaildemo/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zhengsr.emaildemo;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.widget.TextView;
7 |
8 | import com.android.zemaillib.ZMailManager;
9 | import com.android.zemaillib.callback.IEmailSendListener;
10 |
11 |
12 | public class MainActivity extends AppCompatActivity implements IEmailSendListener {
13 | private static final String TAG = "MainActivity";
14 | private static final String SEND_EMAIL = "xxxx@163.com";
15 | private static final String TO_EMAIL = "xx@163.com";
16 | private static final String PASSWORD = "xxxxx";
17 | private TextView mTextView;
18 | @Override
19 | protected void onCreate(Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | setContentView(R.layout.activity_main);
22 | mTextView = findViewById(R.id.textview);
23 |
24 | String imageUrl = "http://img.my.csdn.net/uploads/201309/01/1378037235_7476.jpg";
25 | String[] files = new String[]{"/mnt/usb/019A-6166/test.png","/mnt/usb/019A-6166/test2.png"};
26 | //发送邮件
27 |
28 | /**
29 | * fromAddr -- 发送人邮箱,不填报错
30 | * nickName -- 发送人的昵称,不写则默认为 test
31 | * password -- 授权码,不填报错,gmail 记得允许权限低的应用可以访问的权限
32 | * host -- 配置 host 服务地址,默认根据发件人的邮箱来,比如 xx@qq.com ,则 host 为 smtp.qq.com
33 | * isSSLvertify -- 是否开启SSL验证,默认开启,开启是端口为465,不开启则为25,建议开启,很多邮箱都需要验证 SSL的
34 | * port -- 根据isSSLvertify,开启是端口为465,不开启则为25,也支持自定义
35 | * subject -- 邮件主题,不写默认 TEST
36 | * content -- 邮件内容,不写默认 This is a test email
37 | * file -- 支持 url 和 本地文件,可多个
38 | * toAddrs -- 收件人,多个多个,必填,不填报错
39 | */
40 | ZMailManager
41 | .fromAddr(SEND_EMAIL)
42 | .nickName("会散步的鱼")
43 | .password(PASSWORD)
44 | //.host("smtp.163.com")
45 | //.isSSLvertify(false)
46 | //.port(25)
47 | .subject("测试邮件")
48 | .content("这是一封测试邮件!")
49 | .file(imageUrl)
50 | // .file(new String[]{imagePath})
51 | .toAddrs(new String[]{TO_EMAIL})
52 | .listener(this)
53 | .send();
54 |
55 | }
56 |
57 | @Override
58 | public void sendStart() {
59 | Log.d(TAG, "zsr --> sendStart: ");
60 | mTextView.setText("正在发送...");
61 | }
62 |
63 | @Override
64 | public void sendFailed(String errorMsg) {
65 | Log.d(TAG, "zsr --> sendFailed: "+errorMsg);
66 | mTextView.setText("发送失败: "+errorMsg);
67 | }
68 |
69 | @Override
70 | public void sendSuccess() {
71 | Log.d(TAG, "zsr --> sendSuccess: ");
72 | mTextView.setText("发送成功,请刷新您的邮箱!");
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/zemaillib/src/main/java/com/android/zemaillib/ZMailManager.java:
--------------------------------------------------------------------------------
1 | package com.android.zemaillib;
2 |
3 | import android.text.TextUtils;
4 |
5 | import com.android.zemaillib.bean.ZEmailBean;
6 | import com.android.zemaillib.callback.IEmailSendListener;
7 |
8 |
9 | /**
10 | * Created by zhengshaorui
11 | * Time on 2018/12/22
12 | */
13 |
14 | public class ZMailManager {
15 |
16 | public static EmailConfig fromAddr(String fromAddr){
17 | return new EmailConfig().fromAddr(fromAddr);
18 | }
19 |
20 |
21 | public static class EmailConfig {
22 | private ZEmailBean mZmailBean;
23 |
24 | public EmailConfig() {
25 | this.mZmailBean = new ZEmailBean();
26 | }
27 |
28 | public EmailConfig fromAddr(String fromAddr){
29 | mZmailBean.fromAddr = fromAddr;
30 | return this;
31 | }
32 | public EmailConfig password(String password){
33 | mZmailBean.password = password;
34 | return this;
35 | }
36 |
37 | public EmailConfig toAddrs(String[] toAddrs){
38 | mZmailBean.toAddrs = toAddrs;
39 | return this;
40 | }
41 | public EmailConfig subject(String subject){
42 | mZmailBean.subject = subject;
43 | return this;
44 | }
45 | public EmailConfig content(String content){
46 | mZmailBean.content = content;
47 | return this;
48 | }
49 | public EmailConfig nickName(String nickName){
50 | mZmailBean.nickName = nickName;
51 | return this;
52 | }
53 |
54 | public EmailConfig file(String url){
55 | mZmailBean.url = url;
56 | return this;
57 | }
58 |
59 | public EmailConfig file(String[] filePath){
60 | mZmailBean.filePaths = filePath;
61 | return this;
62 | }
63 |
64 |
65 | public EmailConfig listener(IEmailSendListener listener){
66 | mZmailBean.listener = listener;
67 | return this;
68 | }
69 | public EmailConfig host(String host){
70 | mZmailBean.host = host;
71 | return this;
72 | }
73 | public EmailConfig isSSLvertify(boolean isSSLvertify){
74 | mZmailBean.isSSLverify = isSSLvertify;
75 | return this;
76 | }
77 |
78 | public EmailConfig port(int port){
79 | mZmailBean.port = port+"";
80 | return this;
81 | }
82 |
83 | public EmailConfig send(){
84 | new ZemailRequest(checkNull(mZmailBean));
85 | return this;
86 | }
87 |
88 |
89 |
90 | /**
91 | * 检查是否有空数据
92 | * @param bean
93 | */
94 | private ZEmailBean checkNull(ZEmailBean bean) {
95 | if (bean != null) {
96 | if (TextUtils.isEmpty(bean.fromAddr)) {
97 | throw new NullPointerException("fromAddr cannot be null !");
98 | }
99 | if (TextUtils.isEmpty(bean.password)) {
100 | throw new NullPointerException("password cannot be null !");
101 | }
102 | if (bean.toAddrs == null || bean.toAddrs.length == 0) {
103 | throw new NullPointerException("toAddrs cannot be null !");
104 | }
105 |
106 | }
107 | return bean;
108 |
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/zemaillib/src/main/java/com/android/zemaillib/ZemailRequest.java:
--------------------------------------------------------------------------------
1 | package com.android.zemaillib;
2 |
3 | import android.os.AsyncTask;
4 | import android.text.TextUtils;
5 |
6 | import com.android.zemaillib.bean.ZEmailBean;
7 |
8 | import java.net.URL;
9 | import java.util.Date;
10 | import java.util.Properties;
11 |
12 | import javax.activation.DataHandler;
13 | import javax.activation.DataSource;
14 | import javax.activation.FileDataSource;
15 | import javax.activation.URLDataSource;
16 | import javax.mail.BodyPart;
17 | import javax.mail.Message;
18 | import javax.mail.Multipart;
19 | import javax.mail.Session;
20 | import javax.mail.Transport;
21 | import javax.mail.internet.InternetAddress;
22 | import javax.mail.internet.MimeBodyPart;
23 | import javax.mail.internet.MimeMessage;
24 | import javax.mail.internet.MimeMultipart;
25 | import javax.mail.internet.MimeUtility;
26 |
27 | /**
28 | * Created by zhengshaorui
29 | * Time on 2018/12/22
30 | */
31 |
32 | public class ZemailRequest {
33 | private static final String TAG = "ZemailRequest";
34 | public ZemailRequest(ZEmailBean bean){
35 | new SendSyncTask(bean).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
36 | }
37 |
38 |
39 |
40 | static class SendSyncTask extends AsyncTask{
41 | ZEmailBean bean;
42 | String errorMsg;
43 | private SendSyncTask(ZEmailBean bean){
44 | this.bean = bean;
45 | }
46 |
47 | @Override
48 | protected void onPreExecute() {
49 | super.onPreExecute();
50 | if (bean.listener != null) {
51 | bean.listener.sendStart();
52 | }
53 | }
54 |
55 | @Override
56 | protected Boolean doInBackground(Void... voids) {
57 | try {
58 | String host ;
59 | if (!TextUtils.isEmpty(bean.host)){
60 | host = bean.host;
61 | }else {
62 | host = new StringBuilder().append("smtp.")
63 | .append(bean.fromAddr.split("\\@")[1].split("\\.")[0])
64 | .append(".com").toString();
65 | }
66 | String port ;
67 | if (!TextUtils.isEmpty(bean.port)){
68 | port = bean.port;
69 | }else{
70 | if (bean.isSSLverify) {
71 | port = "465";
72 | }else{
73 | port = "25";
74 | }
75 | }
76 | Properties props = new Properties();
77 | props.put("mail.smtp.host", host);
78 | if (bean.isSSLverify) {
79 | props.put("mail.smtp.socketFactory.port", port);
80 | props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
81 | props.put("mail.smtp.auth", "true");
82 | props.put("mail.smtp.port", port);
83 | }
84 |
85 | Session session ;
86 | if(bean.isSSLverify){
87 | session = Session.getInstance(props,
88 | new MailAuthenticator(bean.fromAddr,bean.password));
89 | }else{
90 | session = Session.getInstance(props,null);
91 | }
92 | MimeMessage mimeMessage = new MimeMessage(session);
93 | session.setDebug(true);
94 | //设置发送地址
95 | mimeMessage.setFrom(new InternetAddress(bean.fromAddr,bean.nickName,"UTF-8"));
96 | //接收端的Email可以有多个
97 | int count = bean.toAddrs.length;
98 | InternetAddress[] internetAddresses = new InternetAddress[count];
99 | for (int i = 0; i < count; i++) {
100 | internetAddresses[i] = new InternetAddress(bean.toAddrs[i]);
101 | }
102 | mimeMessage.addRecipients(Message.RecipientType.TO,internetAddresses);
103 |
104 | MimeBodyPart mimeBodyPart = new MimeBodyPart();
105 | //内容设置成文本格式
106 | mimeBodyPart.setContent(bean.content, "text/html;charset=utf-8");
107 | Multipart multipart = new MimeMultipart();
108 | multipart.addBodyPart(mimeBodyPart);
109 |
110 | // 文件
111 |
112 | if (!TextUtils.isEmpty(bean.url)){
113 | BodyPart part = new MimeBodyPart();
114 | URL url = new URL(bean.url);
115 | DataSource urlSource = new URLDataSource(url);
116 | DataHandler dataHandler = new DataHandler(urlSource);
117 | // 得到附件本身并至入BodyPart
118 | part.setDataHandler(dataHandler);
119 | // 得到文件名同样至入BodyPart
120 | part.setFileName(MimeUtility.encodeText(urlSource.getName()));
121 | multipart.addBodyPart(part);
122 | }
123 | int leng = bean.filePaths == null ? 0 : bean.filePaths.length;
124 | for (int i = 0; i < leng; i++) {
125 | // 根据文件名获取数据源
126 | BodyPart part = new MimeBodyPart();
127 | DataSource fileSource = new FileDataSource(bean.filePaths[i]);
128 | DataHandler dataHandler = new DataHandler(fileSource);
129 | // 得到附件本身并至入BodyPart
130 | part.setDataHandler(dataHandler);
131 | // 得到文件名同样至入BodyPart
132 | part.setFileName(MimeUtility.encodeText(fileSource.getName()));
133 | multipart.addBodyPart(part);
134 | }
135 |
136 | //发送
137 | mimeMessage.setSubject(bean.subject);
138 | mimeMessage.setSentDate(new Date());
139 | mimeMessage.setContent(multipart);
140 |
141 | Transport.send(mimeMessage,bean.fromAddr,bean.password);
142 | } catch (Exception e) {
143 | e.printStackTrace();
144 | errorMsg = e.toString();
145 | return false;
146 | }
147 |
148 | return true;
149 | }
150 |
151 | @Override
152 | protected void onPostExecute(Boolean aBoolean) {
153 | super.onPostExecute(aBoolean);
154 | if (aBoolean){
155 | if (bean.listener != null) {
156 | bean.listener.sendSuccess();
157 | }
158 | }else{
159 | if (bean.listener != null) {
160 | bean.listener.sendFailed(errorMsg);
161 | }
162 | }
163 | }
164 | }
165 | }
166 |
--------------------------------------------------------------------------------