我用java mail发送用户注册验证邮件,邮件能正常发送,但是发送时,邮件中含有注册验证的超链接,不知道为什么系统会自动访问该超链接,以至于用户点击该超链接时,链接已失效?这是为什么?还请帮忙解答一下,我该如何做?以下是我的代码:
final String registerUrl = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/service/portal/user/emailVerify?userName=" + name +"®isterId=" + registerId.toString();
final MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage,true,"UTF-8");
message.setSubject("用户注册确认");
message.setTo(email);
message.setFrom("xxx@xxx.com");
Map<String, Object> model = new HashMap<String, Object>();
model.put("user", user);
model.put("domain", registerUrl);
String text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "registration-confirmation.vm","UTF-8", model);
message.setText(text, true);
}
};
try{
Thread thread = new Thread(){//异步发送邮件
public void run(){
javaMailSender.send(preparator);
}
};
thread.start();
}catch(MailException e) {
e.printStackTrace();
}
具体发送邮件是在spring中配置的,用的是JavaMailSenderImpl,我看不出是哪儿的问题,麻烦帮忙看看。spring的配置如下:
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.exmail.qq.com" />
<property name="port" value="25" />
<property name="username" value="xxx@xx.com" />
<property name="password" value="xxx" />
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.timeout">25000</prop>
</props>
</property>
怪我咯2017-04-17 11:46:28
非根治方案:
改成非超連結,讓使用者自行複製存取...
改成驗證碼模式,設定專門的驗證頁面,透過電子郵件發送驗證碼...
改成二次訪問的方式...你說講的系統訪問應該不是瀏覽器訪問,那麼只是單純的GET請求,不會運行頁面中的JS
因此,可以設定一個中轉的驗證頁面,透過瀏覽器運行JS跳到真正的一次性的驗證頁面...
如樓上那樣透過檢查cookies/useragent之類的參數來區分...