Playframework 在电子邮件中嵌入URL
以下是我的设想:Playframework 在电子邮件中嵌入URL,playframework,Playframework,以下是我的设想: 用户向系统注册他/她自己 系统发送确认电子邮件 用户单击电子邮件中的URL以完成注册 在第二步中,我试图在电子邮件中嵌入“激活”URL(由@Controller.action()解析)。 电子邮件将由从Mailer扩展的自定义类发送。 我通过阅读下面的页面为开发和生产服务器设置了“application.baseUrl”,该页面解释了application.baseUrl的设置。 (app/views/registerer.txt) (app/notifiers/mailss
Click below to confirm user registration:
http://www.realaddressgoeshere.com/registerer/activateuser?token=sometokengoeshere
但我得到:
Click below to confirm user registration:
http://127.0.0.1:9000/registerer/activateuser?token=sometokengoeshere
我缺少什么?您是否将
应用程序模式
与框架id
相混淆?在应用程序配置的下一行中,%prod
指的是框架idprod
。它不涉及应用程序模式PROD
%prod.application.baseUrl=http://www.realaddressgoeshere.com/
如果希望该设置生效,则必须使用
playid
命令将框架id设置为“prod”。有关更多信息,请参阅。我猜您在生产中使用的是apache之类的web服务器
默认情况下,仅当请求对象为null时(从作业调用邮件时),才使用播放中的“application.baseUrl”。下面是框架中的代码
String base = Http.Request.current() == null ? Play.configuration.getProperty("application.baseUrl", "application.baseUrl") : Http.Request.current().getBase();
从控制器调用邮件时,将调用“Http.Request.current.getBase()”方法,该方法可以http://127.0.0.1:9000“如果您在前端服务器后面运行
可能服务器中进行了一些调整以正确传递请求。另一种可能是手动设置url的基本部分
在MailSender类中,可以将url保存在静态变量中
private static String APPLICATION_URL = Play.configuration.getProperty("application.baseUrl");
将其添加到sent方法中
public class MailSender extends Mailer {
public static void registration(User user, String token) {
String applicationUrl = APPLICATION_URL;
setSubject("User Registration Confirmation"));
addRecipient(user.email);
setFrom("XXXSystem <auto-mail@xxxsystem.com>");
send(user, token, applicationUrl);
}
}
以防万一你还需要它,或者其他人也有同样的问题 由于您在Apache服务器后面运行,假设您使用mod_proxy和ProxyPass指令将请求代理到localhost:9000,那么实际上可以保留从传入请求到代理主机的原始主机行,而不是localhost:9000(或为ProxyPass指令指定的任何主机名)。为此,请将以下指令添加到apache2 VirtualHost配置中:
ProxyPreserveHost On
有关更多信息,请查看。谢谢您的解释!这很清楚,也很容易理解。Play应用程序在apache后面运行,我将采用您提供的Play-side解决方案。我还要检查apache端的调优。
private static String APPLICATION_URL = Play.configuration.getProperty("application.baseUrl");
public class MailSender extends Mailer {
public static void registration(User user, String token) {
String applicationUrl = APPLICATION_URL;
setSubject("User Registration Confirmation"));
addRecipient(user.email);
setFrom("XXXSystem <auto-mail@xxxsystem.com>");
send(user, token, applicationUrl);
}
}
${applicationUrl}@{Registerer.activateUser(token)}
ProxyPreserveHost On