使用 Gradle 发送电子邮件 [英] Sending email using Gradle

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

问题描述

我写了一个任务(实际上是从 Internet 复制的),它将电子邮件发送到给定的电子邮件.但是当我运行它时,我得到 java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage 异常.我在依赖项中包含了 compile group: 'javax.mail', name: 'javax.mail-api', version: '1.5.1' 但仍然得到这个.这是任务

I have written a task (actually copied from Internet), it sends email to given email. But when I run it, I get java.lang.ClassNotFoundException: javax.mail.internet.MimeMessage exception. I have included compile group: 'javax.mail', name: 'javax.mail-api', version: '1.5.1' in dependencies but still getting this. Here is the task

apply plugin: 'com.android.application'

class MailSender extends DefaultTask {

    @TaskAction
    def sendMail(){
        def mailParams = [
                mailhost: "smtp.gmail.com",
                mailport:"465",
                subject: "Email Recieved",
                messagemimetype: "text/plain",
                user: "allaudinqazi@gmail.com",
                password:"", // 
                enableStartTLS:"true",
                ssl:"true"
        ]
        ant.mail (mailParams) {
            from (address:'allaudinqazi@gmail.com')
            to (address:'allaudinqazi@gmail.com')
        }
    }
}

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'

    defaultConfig {
        applicationId "uk.org.sportscotland.app"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 3
        versionName "1.1.1"
    }

    dexOptions {
        javaMaxHeapSize "2g"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile files('libs/org.apache.http.legacy.jar')
    compile fileTree(dir: 'libs', include: 'Parse-1.7.0.jar')
    compile 'com.koushikdutta.ion:ion:2.+'
    compile group: 'javax.mail', name: 'javax.mail-api', version: '1.5.1'
}

ext {
    fileName = "SSV01"
}

task copyToDropbox(type: Copy){
    from "build/outputs/apk/app-debug.apk"
    into "F:/folder/Dropbox/Builds/SS"
    rename {
        fileName + ".apk"
    }
}

task mail(type: MailSender){}

推荐答案

您错误地将 javax.mail 添加到 compile 配置.由于这是在构建时需要的,因此您需要将其添加到 buildscript 依赖项中.

You have incorrectly added javax.mail to the compile configuration. Since this is needed at build time you will need to add it to the buildscript dependencies.

例如:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'javax.mail:javax.mail-api:1.5.1'
    }
}

更多信息这里

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

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