我用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>
Never encountered it before. Was the email content parsed somewhere in the middle? You can try printing the userAgent of the access link to see if you can find out which link is causing the problem.
Non-radical solution:
Changed to non-hyperlink, allowing users to copy and access...
Change to verification code mode, set up a special verification page, and send verification codes by email...
Change to a secondary access method... The system access you are talking about should not be browser access, so it is just a simple GET request and will not run the JS in the page
Therefore, you can set up a transit verification page and run JS through the browser to jump to the real one-time verification page...
As above, distinguish by checking parameters such as cookies/useragent...