我在 JBoss 5.1 中每天运行一个计划任务来发送生日祝福。
邮件内容是 HTML,我在邮件中嵌入了图像。
现在我想获取该图像的嵌入路径,如何在非servet环境中获取图像的路径。
当然,我可以将图像放置在静态位置并访问它们,为此我不想对路径进行硬编码。
该图像位于“WebContent/images/birthday.jpg”位置。
I have a scheduled task running in JBoss 5.1 on a daily basis for sending birthday wishes.
The mail content is HTML and I embed images in the mail.
Now I would like to get the path of that image for embedding, how would it be possible to get path of image in a non-servelt environment.
Ofcourse I could have placed the images at a static location and accessed them, for which I don't want to hardcode the path.
The image is at "WebContent/images/birthday.jpg" location.
发布评论
评论(1)
您如何生成电子邮件内容?这些也是静态 html 文件吗?
如果您要使用简单的静态 html 文件,则必须对图像路径进行硬编码。没有其他办法解决这个问题。
您可以编写一个简单的 Java 应用程序,它作为独立应用程序运行(没有任何服务器、servlet 等),它将创建电子邮件内容。
如果您愿意,Java 代码也可以为您发送电子邮件。
这些是您可以执行的一些操作
您将能够轻松地为多个用户重新设计 html 内容。
使用属性文件的示例。
创建一个文件,例如:“email_template.properties”
在文件中输入以下内容并保存。
image_server=http://www.mywebsite.com
image_folder=/WebContent/images/
创建一个 java 程序来创建 html 电子邮件,并使用属性文件生成图像位置。
} catch (IOException e)
{
//
}
你明白了 使用纯 html,您将不得不进行硬编码。
但是,如果您使用简单的 java 文件,您可以获得更大的灵活性。
如果您需要代码从 java 发送电子邮件,请查看此链接。
如何通过 Java 应用程序发送电子邮件GMail、雅虎还是 Hotmail?
How are you generating the email content? Are these also static html files?
If you are going to use simple static html files, you will have to hard code the image paths. There is no other way around it.
You could write a simple Java application, which runs as a standalone application (without any servers,servlets etc), which will create the email content.
The java code can send out the emails for you too if you want.
These are some of the things you can do, if you use java
You will be able to easily redesign the html content for multiple users.
An example of using property files.
Create a file ex: "email_template.properties"
Enter the following into the file and save it.
image_server=http://www.mywebsite.com
image_folder=/WebContent/images/
Create a jave program to create your html email, and use the property file to generate the image locations.
} catch (IOException e)
{
//
}
You get the idea. using plain html you will have to hard code.
However if you use a simple java file you can get more flexibility.
If you need code to send out email from java, check this link out.
How can I send an email by Java application using GMail, Yahoo, or Hotmail?