Sending mail with embedded URL in Struts 2(在 Struts 2 中发送带有嵌入 URL 的邮件)
问题描述
对于我公司的项目,我必须发送包含嵌入式 URL 的电子邮件,系统会提示用户关注这些 URL.
For a project for my company, I have to send emails containing embedded URLs, which the user will be prompted to follow.
例如,一个人在网站上注册,然后 Struts2 应用程序会向该人发送一封电子邮件,其中有一个 URL 以确认订阅.
For example, a person registers on the website, and then the Struts2 application sends an email to that person in which there is a URL to confirm the subscription.
到目前为止,表单提交和发送电子邮件(从操作内部)都可以正常工作.我遇到的问题是我找不到生成要嵌入邮件正文的 URL 的方法.
So far, the form submission, and sending the email (from inside the action), work just fine. The problem on which I'm stuck is that I can't find a way to generate the URL I'd like to embed in the mail body.
我一定是做错了,但我在想类似以下的事情:
I must be doing it the wrong way, but I was thinking about something like what follows:
其中会有一个 UrlManager
(框架可以提供的东西)和一个方法 getUrlForAction()
,它获取一个动作及其参数作为输入和输出一个包含相应 URL 的字符串(如 http://mysite.mycompany.com/confirm?id=xxxxxyyyyyaaaaa
).
where there would be a UrlManager
(something that could be made available by the framework) with a method getUrlForAction()
that gets an action and its parameters as input and that outputs a String containing the corresponding URL (like http://mysite.mycompany.com/confirm?id=xxxxxyyyyyaaaaa
).
有没有人对如何做到这一点有任何想法或指示?
Does anyone have any ideas or pointers on how to do that?
我尝试使用 UrlProvider
,但在调用 determineActionUrl
时出现空指针异常.可能是我用错了.
I tried using UrlProvider
, but I get a null pointer exception on the determineActionUrl
call. Maybe I'm using it the wrong way.
推荐答案
你需要在你的action中创建属性(依赖)
You need to create the properties (dependencies) in your action
然后在动作中你可以写类似的东西
then in the action you could write something like
这篇关于在 Struts 2 中发送带有嵌入 URL 的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!