For a project for my company, I have to send emails containing embedded URLs that will be offered to the user.
For example, a person signs up on a website, and then the Struts2 application sends an email to the person who has the URL to confirm the subscription.
So far, submitting the form and sending emails (from within the action) work very well. The problem I'm stuck on is that I cannot find a way to create a URL that I would like to embed in the body of the message.
I should be doing it wrong, but I was thinking of something like the following:
public String send() throws Exception { StringBuffer body = new StringBuffer(); HashMap<String, String> params = new HashMap<String, String>(); params.put("id", "xxxxxyyyyyaaaaa"); body.append("Veuillez vous rendre ici :"); body.append(UrlManager.getUrlForAction("action", params)); SendMail sendMail = new SendMail(); sendMail.send(" me@me.fr ", "Information", body.toString()); return SUCCESS; }
where is UrlManager (something that can be accessed by the infrastructure) using the getUrlForAction() method, which receives the action and its parameters as input and displays a string containing the corresponding URL (for example, http://mysite.mycompany.com/confirm?id=xxxxxyyyyyaaaaa ).
Does anyone have any ideas or pointers on how to do this?
EDIT:
I tried using UrlProvider , but I get a null pointer exception in the call to determineActionUrl . Maybe I'm using it the wrong way.
HashMap<String,Object> params = new HashMap<String,Object>(); params.put("id", data.getMd5()); UrlProvider up = new ComponentUrlProvider( new Component(ServletActionContext.getValueStack(ServletActionContext.getRequest())), ServletActionContext.getRequest().getParameterMap()); downloadUrl = up.determineActionURL("confirm", "/", "GET", ServletActionContext.getRequest(), ServletActionContext.getResponse(), params, "http", true, true, true, true);