2
A
回答
5
看來我錯過了附件部分在documentation。我看到的是TODO部分(應該更新btw)。無論如何,這裏比這裏提到的更清晰。
String path = "./web-app/images/grails_logo.jpg"
sendMail {
multipart true
to '[email protected]'
subject "Welcome to Grails!"
body '''
Greetings Earthlings!
'''
attachBytes path,'image/jpg', new File(path).readBytes()
}
有了這個,只要您正確指定了我猜的內容類型,就可以附加任何類型的文件。
0
即使在TLS之上,Grails插件('grails install-plugin mail')也能很好地工作 - 請參閱mac.com發送要求。
然而,對於使用Outlook或其他企業電子郵件系統的,我找到了一個稍微不同的Grails的解決方案resource.xml的使用和Spring JavaMail的輔助類:
1)添加以下的myapp /在grails-app/conf/spring/resources.xml(見下文)
2)根據需要在您的業務服務中定義服務。
3)添加一些導入 - 完成! 進口的javax.mail.internet.MimeMessage 進口org.springframework.core.io.FileSystemResource 進口org.springframework.mail.javamail.MimeMessageHelper
高清mailSender
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- Mail service -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="mail.munger.somecorp.com"/>
<property name="port" value="25"/>
<property name="javaMailProperties">
<props>
<prop key="mail.debug">false</prop>
</props>
</property>
</bean>
<!-- more bean definitions go here... -->
</beans>
Java代碼添加附件:
MimeMessage message = mailSender.createMimeMessage()
MimeMessageHelper helper = new MimeMessageHelper(message, true)
for (String recipients : [ customer1, customer2, customer3, customer4 ].findAll { it != null })
{
helper.addTo(str);
}
helper.setFrom("")
helper.setSubject(aSubject)
helper.setText("...")
FileSystemResource fileResource =
new FileSystemResource(new File(tempFile))
helper.addAttachment(tempFile.substring(tempFile.lastIndexOf("/") + 1), fileResource, "application/pdf")
相關問題
- 1. 無法使用Grails Mail插件
- 2. Grails Mail插件sendMail鉤子
- 3. Grails Mail插件不工作
- 4. 設置SMTP信封MAIL FROM使用grails異步郵件插件
- 5. Grails:在插件中使用Resources插件
- 6. 如何使用Java Mail在郵件中附加PDF?
- 7. Zend Mail 2.0附件
- 8. 使用Mail Gem和Paperclip解碼附件
- 9. 無法使用Java Mail發送附件
- 10. 使用Grails異步郵件插件發送多個附件
- 11. mail()MIME附件只是說文件中的文件位置
- 12. PHP mail() - 一旦添加文件附件,HTML將作爲附件顯示
- 13. grails插件獲取gmail附件
- 14. PHP Pear Mail - 添加zip附件
- 15. JAVA MAIL API:無法將xls文件附加到郵件
- 16. 使用groovy在SoapUI中附加文件
- 17. 使用maven在文件中附加值
- 18. 使用grails郵件插件發送電子郵件中的PDF附件
- 19. PHP Mail附件顯示noname.txt
- 20. 在Grails插件中使用Spring DSL
- 21. 在grails中使用springcache插件
- 22. 如何加快使用Java Mail保存附件的時間?
- 23. 使用PackageMaker安裝Mail插件?
- 24. 使用PhoneGap EMailComposer插件附加文件時出錯
- 25. 我可以爲Android Mail Client創建附加組件或插件嗎?
- 26. 在pipedrive中附加文件
- 27. 使用Markdown郵件附加Excel文件
- 28. 使用php附加文件到郵件
- 29. 如何在Mail Composer中附加圖片?
- 30. 附加組件媒體中心插件
正確,使用郵件0.9,我已經能夠獲得附件正如你所示。 – 2010-02-19 13:33:33