golang邮箱发送验证码
常用邮箱:
QQ 邮箱
POP3 服务器地址:qq.com(端口:995)
SMTP 服务器地址:smtp.qq.com(端口:465/587)
163 邮箱:
POP3 服务器地址:pop.163.com(端口:110)
SMTP 服务器地址:smtp.163.com(端口:25)
126 邮箱:
POP3 服务器地址:pop.126.com(端口:110)
SMTP 服务器地址:smtp.126.com(端口:25)
代码如下:
首先导入包:
"net/smtp"
"math/rand"//随机数
"time"
"fmt"
"log"
定义一个Map存放邮箱号及对应随机码
var Code = make(map[string]int) //key为Email,value为随机码
邮箱发送验证码
func SendEmail(email string) int {//smtp.PlainAuth()// 参数1:Usually identity should be the empty string, to act as username// 参数2:username//参数3:password//参数4:hostauth := smtp.PlainAuth("", "18510122672@163.com", "此处填写邮箱密码", "smtp.163.com")to := []string{"1354428522@qq.com"}//发送随机数为验证码// Seed uses the provided seed value to initialize the default Source to a// deterministic state. If Seed is not called, the generator behaves as// if seeded by Seed(1). Seed values that have the same remainder when// divided by 2^31-1 generate the same pseudo-random sequence.// Seed, unlike the Rand.Seed method, is safe for concurrent use.rand.Seed(time.Now().Unix())// Intn returns, as an int, a non-negative pseudo-random number in [0,n)num := rand.Intn(10000)//发送内容使用base64 编码,单行不超过80字节,需要插入\r\n进行换行//The msg headers should usually include// fields such as "From", "To", "Subject", and "Cc". Sending "Bcc"// messages is accomplished by including an email address in the to// parameter but not including it in the msg headers.str := fmt.Sprintf("From:18510122672@163.com\r\nTo:1354428522@qq.com\r\nSubject:verifycode\r\n\r\n,%d,\r\n.", num)//邮件格式msg := []byte(str)err := smtp.SendMail("smtp.163.com:25", auth, "18510122672@163.com", to, msg)if err != nil {log.Fatal(err)}return num
}
golang邮箱发送验证码相关推荐
- Spring Boot 整合163或者qq邮箱发送验证码
前记 最近做的项目中注册功能要用到验证码,本来想用阿里云的短信服务,但是有点小贵,就另辟捷径,选择了用邮箱来发送验证码.记录一下整合过程,也希望能帮助一些有需要的人. 正文 1.Spring Boot ...
- java邮箱发送验证码_java 邮箱发送验证码
packagecom.*******.util.email;importorg.apache.commons.mail.EmailException;importorg.apache.commons. ...
- 邮箱发送验证码工具类
1.邮箱支持引入到pom <dependency><groupId>org.springframework.boot</groupId><artifactId ...
- Python使用QQ邮箱发送验证码
向指定对象发送验证码 在做一些个人的demo或者实战项目等,涉及登录验证的,可以通过该方式实现一个简易的邮箱发送验证码. 该方法使用了Python的smtplib第三方库,需要保证发送者的QQ邮箱开通 ...
- SpringBoot实现邮箱发送验证码(QQ,163等同理)
SpringBoot实现邮箱发送验证码 准备工作(依赖和yml文件的配置) 邮件的发送代码 补充 准备工作(依赖和yml文件的配置) 我们要远程操纵邮箱就需要获得每个邮箱的密钥: 1.先进入你的qq邮 ...
- 实战总结:邮箱发送验证码
java邮箱发送验证码 目前项目中需要同时支持短信和邮箱验证,短信用的是腾讯云就不多说了,在此分享一下邮箱验证码发送. 首先,作为发送邮箱,需要开启POP3/SMTP/IMAP,登录邮箱–设置–账户– ...
- 邮箱发送验证码和短信发送验证码的学习笔记
邮箱发送验证码 //邮箱验证码public static boolean sendEmail(String emailaddress,String code) {try {HtmlEmail emai ...
- SpringBoot通过qq邮箱发送验证码
SpringBoot通过qq邮箱发送验证码 1.开启qq授权码 2.编写配置文件 spring:#邮箱验证mail:##163 smtp.163.com(反垃圾系统发送不了了)##qq smtp.qq ...
- Java 实现邮箱发送验证码——QQ邮箱为例
JAVA实现使用QQ邮箱发送验证码功能 QQ邮箱设置 第一步 ,打开QQ邮箱(地址:https://mail.qq.com/): 第二步 ,登录后点击设置 第三步,点击账户,下拉找到POP3/IMAP ...
最新文章
- Java 处理0x00特殊字符
- oracle10g只导出某个用户所拥有的数据库表
- 政策解读:《智能硬件产业创新发展专项行动(2016-2018年)》(上)
- msys2安装gcc、g++编译器
- java list装3组数据_数组转List的3种方法和使用对比!
- Linux 常用命令随笔(二)
- C++安全方向(三):3.8 openssl单项散列章节总结
- 如何利用ThoughtWorks.QRCode 生成二维码
- win7安装中文语言包
- FastReport 2022-2 VCL 企业版-FastReport
- 利用PTGui制作全景图并用Pano2VR生成SWF文件
- IPV6 阿里DDNS
- 毫米波雷达产业链全景
- 【linux内核分析与应用-陈莉君】设备驱动模型
- [渗透]缓慢的HTTP拒绝服务攻击原理、利用和防范
- cpar文件的导入导出及注意事项
- deepin 下 WPS for linux字体显示问题[已解决]
- 【MyBatis 面试题】
- 【机器学习】采用信息增益、信息增益率、基尼指数来建造决策树。
- 请问,电子产品中常用的12V转5V的DCDC电源芯片有哪些