2012-12-29 28 views
3

在您需要的grails郵件插件中,假設您使用服務中的grails郵件,請在服務中定義您的內聯圖像數據。grails郵件:從電子郵件中的數據庫渲染個人資料圖片

你做到這一點,像這樣在你的service.groovy

inline 'header', 'image/jpg', new File('./web-app/images/mailAssets/alert_header_pre.png') 

服務定義中,可以說:

def mailService 
def contactUser(userName, email) { 
    mailService.sendMail { 
     multipart true 
     to email 
     from "[email protected]" 
     subject "Hello from grails-mail" 
     text "Hallo from grails-mail multipart text modus" 
     html view:"/alert/test", model:[name:userName] 
     inline 'header', 'image/jpg', new File('./web-app/images/mailAssets/alert_header_pre.png') 
     inline 'footer', 'image/jpg', new File('./web-app/images/mailAssets/suchebottomre.gif') 
    } 
} 

現在,應用程序被渲染頁腳和標題圖片,好。

好了,現在這個項目的規劃者的計劃是在他們的電子郵件來呈現來自數據庫的個人資料照片(約15.000用戶) - 可以,如果再怎麼能這樣沒有每個用戶的個人資料圖片聲明裏面的服務來實現。常規?此外,這些圖片存儲在我的應用程序以外的亞馬遜S3。這可能是郵件插件的邊界,還是有可能得到這個工作?如果不可能做到這一點,你會爲那些計劃和創意人員提供什麼樣的選擇?任何意見都歡迎。

回答

2
  1. 循環遍歷用戶。
  2. 使用grails-aws-plugin從S3獲取相應的圖片。
  3. 插入圖片到電子郵件
  4. 使用郵件插件

這樣,你不必聲明它在服務發送郵件。您可以從S3下載圖片以將它們用作嵌入式圖片,也可以使用S3提供的網址。

訪問該文件內聯用法:

def file = aws.s3().on(bucket).get(name, path) 

要獲得公共網址:

def url = aws.s3().on(bucket).url(name, path) 
+0

感謝您對您所提供的信息資料 – thegrunt

相關問題