2012-07-18 20 views
2

我已經安裝了this plugin,我想從一個服務/域類方法來發送郵件,我在做這樣的如何從一個域/服務發送郵件的Grails

class TrainingService { 
     def mailService 
     public def sendMail() { 
     mailService.sendMail { 
      multipart true 
      to "[email protected]" 
      subject "Hello," 
      body 'How are you?' 

      } 
} 

我遇到錯誤「不能調用如何解決這個問題

+0

你在哪裏打電話給sendMail?你是否這樣稱呼它:'trainingService.sendMail()'?你的TrainingService是否定義了:你調用它的'def trainingService'? – Weezle 2012-07-18 22:04:22

+0

我從控制器呼叫trainingService.sendMail() – n92 2012-07-19 07:35:10

回答

1

我缺少「from」屬性,如果您使用的是多部分電子郵件,您還應該從我的代碼中填寫電子郵件的其他部分:

mailService.sendMail { 
      multipart true 
      from '"Some account" <[email protected]>' 
      to '[email protected]' 
      bcc emailAddresses.toArray() 
      subject dto.title 
      body emailPart1 
      html g.render(
        template: 'emailNotification', 
        model: [ name: dto.name ] 
      ) 

} 
0

您配置了SMTP服務器嗎?您需要在配置文件中使用這些條目才能使郵件生效。你有這些嗎?

grails { 
    mail { 
        host = "hostname" 
        pop_port = 25 
        username = "username" 
        password = "password" 
        type = "pop3" 

       } 
} 

,你可以找到關於配置here

+0

是的,我已經配置好了,我可以發送來自控制器的郵件,而不是來自域/服務類 – n92 2012-07-19 11:49:14

+0

嘗試grails clean並運行應用程序,看看你是否得到錯誤。 – allthenutsandbolts 2012-07-19 13:02:08

0

當我是「從」傳遞變量打來電話,我得到這個錯誤的詳細信息「到」成是使用sendmail的方法。嘗試重命名sendMail方法並確保您沒有任何衝突的變量名稱。

相關問題