JS验证码邮件
js
var time = 30;
var canSend = true; function f5() {
if (canSend) {//判断是否要ajax发送刷新验证码 验证码在后台刷新
//alert("验证");
send();
}
if (time == 0) {//时间为0是button设置可用 并且设置可发送
$('#vbtn').attr("disabled", false);
$("#vbtn").text("重新发送")
time = 30;
canSend = true;
} else {//时间不等于0时button设置不可点击 并且不能发送
canSend = false;
$('#vbtn').attr("disabled", true);
time--;
setTimeout(function () {
$("#vbtn").text(time + "秒后可重新发送")
f5();
}, 1000)
}
} function send() {
$.ajax({
type : "post",
url : getRootPath() + "/sendMail",
data : {
"mail" : $("#mail").val()
},
success : function(result) {
alert("send success");
}
})
} // 得到绝对路径
function getRootPath() {
// 获取当前网址,如: http://localhost:9527/zdss-web/login/login.do
var curWwwPath = window.document.location.href;
// console.log("当前网址:" + curWwwPath); // 获取主机地址之后的目录,如:zdss-web/login/login.do
var pathName = window.document.location.pathname;
// console.log("当前路径:" + pathName); var pos = curWwwPath.indexOf(pathName);
// console.log("路径位置:" + pos); // 获取主机地址,如: http://localhost:9527
var localhostPath = curWwwPath.substring(0, pos);
console.log("当前主机地址:" + localhostPath); // 获取带"/"的项目名,如:/zdss-web
var projectName = pathName
.substring(0, pathName.substr(1).indexOf('/') + 1);
console.log("当前项目名称:" + projectName);
console.log(localhostPath + projectName);
return localhostPath + projectName;
}
/**
* Created by Administrator on 2017/10/30.
*/
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JsMail</title>
</head>
<body>
<body>
<p>输入邮箱</p><input type="text" id="mail"/>
<button id="vbtn" onclick="f5()">发送</button>
</body> <script src="js/jquery-3.2.1.min.js"></script>
<script src="js/F5VerificationCode.js"></script>
</body>
</html>
java 需导入javamail jar包
package com.acm.web; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
import java.util.UUID; /**
* Created by Administrator on 2017/10/30.
*/
@Controller
public class MailController { @ResponseBody
@RequestMapping("sendMail")
public String SendMail(String mail) throws MessagingException { UUID uuid = UUID.randomUUID();
String code = uuid.toString().substring(0,6);
System.out.println(code); Properties properties = new Properties();
properties.put("mail.transport.protocol", "smtp"); // 连接协议
properties.put("mail.smtp.host", "smtp.qq.com"); // 主机名
properties.put("mail.smtp.port", 465); // 端口号
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.ssl.enable", "true"); // 设置是否使用ssl安全连接 (一般都使用)
properties.put("mail.debug", "true"); // 设置是否显示debug信息 true 会在控制台显示相关信息
// 得到回话对象
Session session = Session.getInstance(properties);
// 获取邮件对象
Message message = new MimeMessage(session);
// 设置发件人邮箱地址
message.setFrom(new InternetAddress("发件邮箱")); // 设置收件人地址
message.setRecipients(MimeMessage.RecipientType.TO, new InternetAddress[]{new InternetAddress(mail)});
// 设置邮件标题
message.setSubject("验证码邮件");
// 设置邮件内容
message.setContent("验证码为" + code, "text/html;Charset=UTF-8");
// 得到邮差对象
Transport transport = session.getTransport();
// 连接自己的邮箱账户
transport.connect("发件邮箱", password); // password 为在qq邮箱内的到的授权码
// 发送邮件
transport.sendMessage(message, message.getAllRecipients()); return null;
} }
spring-mvc.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean> <!-- 扫描web相关的bean -->
<context:component-scan base-package="com.acm.web" /> <!--两个标准配置 -->
<!-- 将springmvc不能处理的请求交给tomcat -->
<mvc:default-servlet-handler/>
<!-- 能支持springmvc更高级的一些功能,JSR303校验,快捷的ajax...映射动态请求 -->
<mvc:annotation-driven/> </beans>
JS验证码邮件的更多相关文章
- js 验证码 倒计时60秒
js 验证码 倒计时60秒 <input type="button" id="btn" value="免费获取验证码" /> & ...
- js验证码有效时间倒计时
js验证码有效时间倒计时 <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type& ...
- 纯js验证码
纯js验证码 <!DOCTYPE html> <html> <head> <title>纯js验证码</title> </head&g ...
- Node.js定时邮件的那些事儿
近开发一个项目,需要在Node.js程序里实现定期给管理员发邮件的功能. 笔者平时只会在Web界面收发邮件.对邮件的原理完全不懂(可能大学教过,然而全忘了),直到要解决这个问题.请教了几个业务的同事, ...
- easyui page添加文本,js验证码
onLoadSuccess: function (db) { //db是后台数据的返回结果集 $.ajax({ url: "AjaxSource/Buex.ashx", data: ...
- js 验证码倒计时
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- angular.js 验证码注册登录
css部分 header{ height: 50px; line-height: 50px; display: flex; } .callback{ text-align: left; display ...
- node.js发邮件
在node上使用第三方类库(nodemailer)发邮件是一件很esay的事情:) app.js 以QQ邮箱为例 var nodemailer = require('nodemailer'); v ...
- 项目一:第八天 1、前台系统导入 实现客户注册 发验证码,邮件 springdata-redis存储数据 3、实现客户登陆
1 前台系统客户注册功能 页面:signup.html 1.1 验证手机号是否注册(邮箱同样) 1. 使用Jquery-validate插件进行相关校验,使用校验规则 <input type=& ...
随机推荐
- Java应用常用性能分析工具
Java应用常用性能分析工具 好的工具有能有效改善和提高工作效率或加速分析问题的进度,笔者将从事Java工作中常用的性能工具和大家分享下,如果感觉有用记得投一票哦,如果你有好的工具也可以分享给我 工具 ...
- 阿里云 配置ssl 在nginx上
写给自己的备忘录: 很乱 如果你也是 配置nginx ssl 可以给我留言 ,我是为了 捣鼓微信小程序后台 需要https 阿里云有免费一年的 ssl服务 链接 https://www.aliyun. ...
- C#与Excel的交互示例
//这里加添加一个Excel对象的包装器.就是添加一个引用 using System; using System.Drawing; using System.Collections; using Sy ...
- SpringCloud系列三:SpringSecurity 安全访问(配置安全验证、服务消费端处理、无状态 Session 配置、定义公共安全配置程序类)
1.概念:SpringSecurity 安全访问 2.具体内容 所有的 Rest 服务最终都是暴露在公网上的,也就是说如果你的 Rest 服务属于一些你自己公司的私人业务,这样的结果会直接 导致你信息 ...
- python abc模块
面向对象的设计中,抽象类,接口这些必不可少的东西,在python中是如何提现的呢? python作为一个动态语言,没有强类型的检查,而是以鸭子类型的方式提现,在执行的时候python不严格要求你必须是 ...
- 移动端UL列表无法平滑向下滚动问题
问题说明: 移动端向上滑动后,,列表无法自动滚动到底部~~而是类似屏幕"沾手"的效果(手离开屏幕直接停止在当前~列表不会自动向下滚动一段) 问题原因: 页面中存在如下代码: 当前页 ...
- [FE] 有效开展一个前端项目1
今天的前端如果没有用到 npm,效率是比较低的:所以要从使用的工具来讲. 1. 一切都依赖于 nodejs: 下载一个 linux 的源码包就可以开始安装了. $ wget https://nodej ...
- join() ---- 使用四种不同的分隔符连接数组元素
var a = ['Wind', 'Rain', 'Fire']; var myVar1 = a.join(); // myVar1的值变为"Wind,Rain,Fire" var ...
- MySQL二进制日志(binary log)总结
本文出处:http://www.cnblogs.com/wy123/p/7182356.html (保留出处并非什么原创作品权利,本人拙作还远远达不到,仅仅是为了链接到原文,因为后续对可能存在的一些错 ...
- VUE - 相对路径
background-image背景图片路径问题可以这样解决:1.先在data里面导入这张图片,例如: bg:require('./openIndexBG2.jpg')2 ...