0

I have service which is not invoked by user request, but by task. Now I need to send email from this task, and email contains link to my web application, how can I get full url of my application so that my email can link back to my web application?

Example of service:

@Service
public class MyService {

    @Scheduled(cron="0 */10 * * * *")
    @Transactional
    public void myTask() throws IOException, ParseException
    {
        // Now I have to send email with my app url, but how can I get it here ?
    }

}
newbie
  • 24,286
  • 80
  • 201
  • 301

1 Answers1

1

You cannot do it, since web application actually doesn't know its own domain name. It can only extract a domain name used to send a request from that request.

Therefore domain name of your application should be a part of configuration, and your task should obtain it from there.

axtavt
  • 239,438
  • 41
  • 511
  • 482