Search code examples
emailgrailssendmail

Grails Send HTML Mail signature of method error


I am trying to figure out how to send html mail with mail send. I am stuck and am getting “No signature of method: applicable for argument types: (null) values: [null]” It is the request id variable that I am trying to pass to the email.

My job is below

import groovy.util.logging.Slf4j
import org.camunda.bpm.client.ExternalTaskClient
import org.camunda.bpm.client.task.ExternalTask
import org.camunda.bpm.engine.ProcessEngines
import org.camunda.bpm.engine.ProcessEngine
import grails.core.GrailsApplication
import edu.andrews.bpm.changeofprogram.EmailReceivedRequestExternalTaskService
import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider
//import edu.andrews.bpm.changeofprogram.StudentApprovalRequestController
import org.springframework.beans.factory.annotation.Value
@Slf4j



class EmailReceivedRequestExternalTaskJob {
    EmailReceivedRequestExternalTaskService emailReceivedRequestExternalTaskService
//    StudentApprovalRequestController studentApprovalRequestController

    @Value('${camunda.bpm.rest.endpoint}')
    String bpmRESTUrl

    static triggers = {
        //                                                                              s m   h D M W Y
        cron name:   'EmailReceivedRequestExternalTask',   startDelay: 10000, cronExpression: '0 */5 * * * ?'
    }

    def execute() {
        // execute job by Polling Camunda BPM for tasks on the topic
        // specified in the Camunda Modeler implementation semantics
        log.info("EmailReceivedRequestExternalTaskService polling of BPM endpoint ${bpmRESTUrl} starting...")

        ExternalTaskClient client = ExternalTaskClient.create()
                .baseUrl(bpmRESTUrl)
                .maxTasks(5)
        // .addInterceptor(new BasicAuthProvider(username, password))
                .build()
        client.subscribe("ProgramChangeReceivedEmail") // topic from Camunda Modeler
                .lockDuration(10000L)
                .handler( { externalTask, externalTaskService ->
                    log.info("Executing external task handler...")
                    Map<String,Object> procVars = externalTask.getAllVariables()
                    Map<String,Object> stuApproveVars = externalTask.getAllVariables()
                    String requestId = procVars.requestId
//                   def String idn  = procVars.idn
                    String email = stuApproveVars.email
                    emailReceivedRequestExternalTaskService.studentApprovalRequest(email)
                    emailReceivedRequestExternalTaskService.studentApprovalRequest(idn)
                    log.info("\texternalTaskVars: ${procVars}")
                    externalTaskService.complete(externalTask)

                }).open()

        client.stop()

        log.info("EmailReceivedRequestExternalTaskService...")
        //log.info(idn)
    }
}

Here is the service call

import grails.gorm.services.Service
import grails.gorm.transactions.Transactional

@Transactional
class EmailReceivedRequestExternalTaskService {

//   def ApplyAcknowledgment(String email, String studentName) {
    def ChangeAcknowledgment(String email, String requestId) {
        sendMail {
            async true
            from "[email protected]"
            to email
            subject "Change of Program"
//            text "Thank you for submitting your change of program request. You will receive an email when it has been approved or denied."
           html view: "/studentApprovalRequest/AcknowledgementEmail", model: [param1: requestId]
//            html view: "/freeclass/FreeClassApplyAcknowledgment"

        }

    }
}

Here is the gsp html info

<html>
 <head>
 </head>
 <body>
                    <p>Thank you for submitting your change of program request. You will receive an email when it has been approved or denied.</p>
                    <p>record: ${requestId}</p>
                    "<p>Thank you.</p>"
</body>
</html>

Solution

  • One of the issues is that it looks like your GSP is expecting a model variable named requestId but EmailReceivedRequestExternalTaskJob is creating a model variable called param1:

    html view: "/studentApprovalRequest/AcknowledgementEmail", model: [param1: requestId]
    

    You could change that to something like this:

    html view: "/studentApprovalRequest/AcknowledgementEmail", model: [requestId: requestId]