关于Java spring MimeMessageHelper发送带有图像的电子邮件
我的文件服务器上有图像,我想将其嵌入到我的电子邮件中。
我可以像这样发送带有本地图像的电子邮件
message.addInline("image1", new ClassPathResource("../../static/images/123.jpg"));
,但如果我想发送带有我的文件服务器图像的电子邮件,则行不通。
message.addInline("image1", new ClassPathResource("http://fileserver.com/images/123.jpg"));
有人知道有办法做到这一点吗?
I have images on my file server which I want to embed into my email.
I can send email with local images like this way
message.addInline("image1", new ClassPathResource("../../static/images/123.jpg"));
but if i want to send email with my file server images, won't work.
message.addInline("image1", new ClassPathResource("http://fileserver.com/images/123.jpg"));
Anybody knows there is a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题已经有一年了,但我想为帮助其他人做出贡献......
Spring 有办法完成你想要的工作。查看 Spring 3x 参考的这一章。 或 Spring2x。
简历中:
您可以从服务器的文件系统中获取您的镜像文件。正如您在参考文献中看到的:
或者从应用程序的类路径的相对路径:
但是,如果您想从具有 URL 的文件服务器发送资源,您可以执行 @Ralph 所说的操作:< /strong>
然后,只需将资源添加到您的消息中:
希望这可以帮助某人......
This question is a year old, but I want to contribute for help other people...
Spring have ways to do the job that you want. Take a look in this chapter of the Spring 3x reference. Or Spring2x.
In resume:
You can obtain your image file from file file system of the server. As you can see in the reference:
Or from a relative path of the classpath of your application:
But, if you want to send a resource from a file server with a URL, you can do something like @Ralph said:
And then, simply add the resource to your message:
Hope this help somebody...
问题是
http://fileserver.com/images/123.jpg
不是类路径资源。如果您从文件系统访问图像,则来自
java.io
包的文件访问类。如果您确实需要通过 http 访问文件,那么您需要先下载该文件。
The problem is that
http://fileserver.com/images/123.jpg
is no Class Path Resource.If you access the image from the file system then file access classes from
java.io
package.If you really need to to access the files over http, then you need to download the file first.