2

次のようにして、localhost のメールにインライン画像を追加しています。

inline 'footerImage', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif').readBytes()

これはうまくいきます。テスト環境にデプロイすると、次のエラーが発生します。

Class
java.io.FileNotFoundException
Message
cannot use ./web-app/images/mailAssets/alert_header_pre.png as an attachment as it does not exist

このログで:

   Line | Method
->>  331 | inline      in grails.plugin.mail.MailMessageBuilder
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     20 | doCall      in de.docinsider.web.NotifierService$_contactUser_closure1
|     39 | sendMail .  in grails.plugin.mail.MailService
|     13 | contactUser in de.docinsider.web.NotifierService
|      7 | doCall . .  in de.docinsider.web.SendController$_closure1
|    195 | doFilter    in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter .  in grails.plugin.cache.web.filter.AbstractFilter
|   1145 | runWorker   in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run         in java.lang.Thread

どうすればこれを回避できますか?

また、リソースローダーを次のように実装することについても考えました。

import org.springframework.context.ResourceLoaderAware
import org.springframework.core.io.ResourceLoader

class SendController implements ResourceLoaderAware {
    @Autowired
    ResourceLoader resourceLoader
    def notifierService

    def index() { }
    def welcome = {
        notifierService.contactUser(params.username, params.email, params.message)
        render view:"/send/feedback", model:[name:params.username, message:params.message]
     }

     void setResourceLoader(ResourceLoader resourceLoader) {
        resourceLoader = resourceLoader
    }

}

これも機能しません。

と:

 inline 'headerImage', 'image/jpg', resourceLoader.getResource('/images/mailAssets/header_top.png')
                inline 'footerImage', 'image/jpg', resourceLoader.getResource('/images/mailAssets/footer_bottom.gif')

サービスで。

4

1 に答える 1

5

これが古いスレッドであることは知っていますが、同じ問題に遭遇したところ、サーバーが画像への実際のパスを認識していないことがわかりました。代わりに、文字列を実際のパスとして使用しています "./web-app/images/mailAssets/ alert_header_pre.png".

この投稿を読むと、実際のパスを取得するのに役立ちます。それ以外の:

inline 'footerImage', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif').readBytes()

これを使って:

inline 'footerImage', 'image/jpg', resourceLoader.getResource("/images/mailAssets/suchebottomre.gif").getFile()

import org.springframework.core.io.Resource or org.springframework.core.io.ResourceLoaderコントローラーを実装implements org.springframework.context.ResourceLoaderAwareして宣言する必要がありますResourceLoader resourceLoader

テスト済み: 製品サーバー: グラスフィッシュ。開発者: Grails 2.3.7.

于 2014-03-27T21:59:40.383 に答える