使用JavaMail API发送电子邮件Android [英] Sending Email Android using JavaMail API

查看:86
本文介绍了使用JavaMail API发送电子邮件Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试不使用此应用程序而直接发送单击按钮上的邮件.实际上我复制了这个

I'm trying to send the mail on button click directly without using this application. Actually i copy this Code from Vinayak Bevinakatti. i follow his code but didnt work, i think i have a problem from SDK VERSION.

Build.app

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.example.coorsdev.sendsms"
    minSdkVersion 14
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'}

推荐答案

我建议这个非常酷的图书馆.如果链接发生变化,将其编译到您的项目中,这是非常简单的继承方法

I suggest this pretty cool library. It is very simple heres how to do it just incase the link change, compile this to your project

//Manifest
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>

//Project gradle
repositories {
    // ...
    maven { url "https://jitpack.io" }
}

//Module gradle
compile 'com.github.yesidlazaro:GmailBackground:1.2.0'

然后使用您只需在OnClick上创建一个实例

Then to use you just have to make an instance on your OnClick

BackgroundMail.newBuilder(this)
            .withUsername("username@gmail.com")
            .withPassword("password12345")
            .withMailto("toemail@gmail.com")
            .withType(BackgroundMail.TYPE_PLAIN)
            .withSubject("this is the subject")
            .withBody("this is the body")
            .withOnSuccessCallback(new BackgroundMail.OnSuccessCallback() {
                @Override
                public void onSuccess() {
                    //do some magic
                }
            })
            .withOnFailCallback(new BackgroundMail.OnFailCallback() {
                @Override
                public void onFail() {
                    //do some magic
                }
            })
            .send();

注意:您可以使用

.withProcessVisibility(false)

希望这会有所帮助.

这篇关于使用JavaMail API发送电子邮件Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆