博主介绍: ✌博主从事应用安全和大数据领域,有8年研发经验,5年面试官经验,Java技术专家,阿里云专家博主,华为云云享专家✌
Java知识图谱点击链接:体系化学习Java(Java面试专题)
💕💕 感兴趣的同学可以收藏关注下 ,不然下次找不到哟💕💕
文章目录
- 1、看看别人的邮件正文都什么样的
- 2、那么这样一个邮件正文怎么做出来的呢?
- 3、我的源码展示
- 4、代码发送上面的精美邮件正文
- 5、如何获取邮箱授权码
1、看看别人的邮件正文都什么样的
下面是发送的邮件正文,是不是很帅气,像一个网页一样,看看华为云的发送验证码的:
然后再看看我做的邮件正文,是不是也有一番韵味呢?
2、那么这样一个邮件正文怎么做出来的呢?
首先网页搜索 QQ 邮箱,或者访问我这里的链接 https://mail.qq.com/?cancel_login=true&from=session_timeout
登录之后,我们点击写邮件,然后点击格式,再点击编辑HTML源码 </>
再这样一个界面我们就可以编写 html 了。
3、我的源码展示
内容中我去掉了自己域名,更换成 www.xxxx.com,各位需要换上自己的域名地址。
这里有以下几点需要注意:
1、要想展示的图片,邮件正文能看,需要用域名可访问的链接。
2、我是自己搭建了一个 Nginx 服务,把图片放上去,换上自己的域名,就可以访问图片了。
上面这部分不清楚的可以问我,我都会解答。
<div>
<div style="font-family: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; line-height: 23.8px; widows: 1; width: 800px; margin: 0px auto; word-break: break-word !important;">
<div style="height: 60px; width: 800px; display: flex; align-items: center; flex-wrap: nowrap; color: rgb(255, 255, 255); border: 1px solid rgb(0, 21, 41); background: rgb(0, 21, 41); word-break: break-word !important;">
<a href="https://www.xxx.com/" style="text-decoration-line: none; word-break: break-word !important;">
<div style="display: flex; align-items: center; flex-wrap: nowrap; width: 490px; word-break: break-word !important;">
<img src="https://www.xxx.com//1_email/logo.png"
style="width: 40px; height: 40px; margin-left: 10px; word-break: break-word !important;">
<div style="margin-left: 5px; color: rgb(255, 255, 255); font-family: 宋体; font-size: 18px; font-weight: bold; word-break: break-word !important;">
爱启云科技
</div>
</div>
</a>
<div style="display: flex; align-items: center; flex-wrap: nowrap; width: 300px; word-break: break-word !important;">
<a href="https://www.xxx.com/"
style="text-decoration-line: none; word-break: break-word !important;">
<div style="width: 100px; height: 30px; line-height: 30px; border-right: 1px solid rgb(191, 191, 191); text-align: center; color: rgb(255, 255, 255); word-break: break-word !important;">
公司官网
</div>
</a><a href="https://www.xxx.com/#/solution"
style="text-decoration-line: none; word-break: break-word !important;">
<div style="width: 100px; height: 30px; line-height: 30px; border-right: 1px solid rgb(191, 191, 191); text-align: center; color: rgb(255, 255, 255); word-break: break-word !important;">
解决方案
</div>
</a><a href="http://xxx:8080/#/login"
style="text-decoration-line: none; word-break: break-word !important;">
<div style="width: 100px; height: 30px; line-height: 30px; border-right: 0px solid rgb(191, 191, 191); text-align: center; color: rgb(255, 255, 255); word-break: break-word !important;">
体验环境
</div>
</a></div>
</div>
<div style="display: flex; flex-wrap: nowrap; width: 801px; height: 720px; border-left: 1px solid rgb(238, 238, 238); word-break: break-word !important;">
<div style="width: 560px; word-break: break-word !important;">
<div style="padding: 20px; height: 408px; word-break: break-word !important;">
<div style="color: rgb(20, 20, 20); line-height: 28px; word-break: break-word !important;">
尊敬的领导您好:
</div>
<div style="color: rgb(20, 20, 20); line-height: 28px; text-indent: 2em; word-break: break-word !important;">
以下是关于我司《村(社区)两委干部管理系统》的资料,详细资料可以点击下方链接查看《村(社区)两委干部管理系统》详细材料或查看邮件附件。
</div>
<div style="display: flex; flex-wrap: nowrap; margin-top: 20px; word-break: break-word !important;">
<div style="padding: 5px 10px; border-radius: 3px; margin-right: 20px; background-color: rgba(0, 0, 0, 0.7); word-break: break-word !important;">
<a href="https://www.xxx.com/1_email/%E7%88%B1%E5%90%AF%E4%BA%91%E7%A7%91%E6%8A%80%E6%9D%91%EF%BC%88%E7%A4%BE%E5%8C%BA%EF%BC%89%E4%B8%A4%E5%A7%94%E5%B9%B2%E9%83%A8%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.pdf"
style="color: rgb(255, 255, 255); text-decoration-line: none; height: 20px; line-height: 20px; word-break: break-word !important;">点击查看详细资料</a>
</div>
<div style="padding: 5px 10px; border-radius: 3px; background-color: rgba(0, 0, 0, 0.7); word-break: break-word !important;">
<a href="http://xxx:8080/#/login"
style="color: rgb(255, 255, 255); text-decoration-line: none; height: 20px; line-height: 20px; word-break: break-word !important;">去体验(请联系销售开通账号)</a>
</div>
</div>
<div style="color: rgb(20, 20, 20); line-height: 28px; margin-top: 40px; word-break: break-word !important;">
谢谢~!
</div>
</div>
<div style="display: flex; align-items: center; flex-wrap: nowrap; height: 250px; width: 558px; border: 1px solid rgb(238, 238, 238); justify-content: center; background: rgb(238, 238, 238); word-break: break-word !important;">
<div style="word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/gzh-qrcode.jpg"
style="width: 150px; height: 150px; margin-left: 10px; word-break: break-word !important;">
<div style="text-align: center; line-height: 28px; word-break: break-word !important;">
企业官方微信公众号
</div>
</div>
<div style="word-break: break-word !important;"><img src="https://www.xxx.com/1_email/qykf.jpg"
style="width: 150px; height: 150px; margin-left: 10px; word-break: break-word !important;">
<div style="text-align: center; line-height: 28px; word-break: break-word !important;">
企业官方客服微信
</div>
</div>
</div>
</div>
<div style="width: 241px; text-align: right; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; word-break: break-word !important;">
<div style="line-height: 40px; color: rgb(9, 109, 217); word-break: break-word !important;">我们的其他产品<span
class="Apple-converted-space"> </span><span
style="font-size: 12px; line-height: 40px; word-break: break-word !important;">(点击查看大图)</span>
</div>
<a href="https://www.xxx.com/1_email/vcms.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/vcms.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
村(社区)两委干部管理系统
</div>
</a><a href="https://www.xxx.com/1_email/di2.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/di2.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
干部测评管理系统
</div>
</a><a href="https://www.xxx.com/1_email/di3.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/di3.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
因私出国境管理系统
</div>
</a><a href="https://www.xxx.com/1_email/di4.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/di4.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
干部因私出国境审批管理系统
</div>
</a><a href="https://www.xxx.com/1_email/di5.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/di5.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
干部研判辅助分析管理系统
</div>
</a></div>
</div>
<div style="height: 40px; width: 800px; display: flex; align-items: center; flex-wrap: nowrap; color: rgb(255, 255, 255); border: 1px solid rgb(0, 21, 41); justify-content: center; background: rgb(0, 21, 41); word-break: break-word !important;">
杭州爱启云网络科技有限公司<span style="margin-left: 40px; word-break: break-word !important;">助力城市数字化改革<span
class="Apple-converted-space"> </span><span
style="margin-left: 10px; word-break: break-word !important;"></span>数智科技赋能未来</span></div>
</div>
<br style="font-family: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; line-height: 23.8px; widows: 1; word-break: break-word !important;">
<p style="font-family: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; line-height: 23.8px; widows: 1; word-break: break-word !important;"></p>
<br style="font-family: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; line-height: 23.8px; widows: 1; word-break: break-word !important;">
</div>
修改好图片链接之后。把代码复制到 QQ 邮箱正文即可:
然后点击返回可视化编辑:
效果如下:
这个东西有两种用法,第一种,直接把邮件的内容复制出来,黏贴到其他邮箱如:网易邮箱、foxmail 这些都可以直接发送。
第二种用法是通过代码发送,我们下面会讲解如何用代发发送,并附上源码。
4、代码发送上面的精美邮件正文
基于 Spring Boot 项目:
pom.xml 引入
<!--邮件-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
代码如下:
package com.pany.camp.email;
/**
*
* @description: 资源工具
* @copyright: @Copyright (c) 2022
* @company: Aiocloud
* @author: pany
* @version: 1.0.0
* @createTime: 2023-07-01 11:35
*/
public class ResourceUtils {
/**
* 获取资源的绝对路径
*
* @since 1.0.0
* @param
* @param path
* @param file
* @return: java.lang.String
* @author: pany
* @version: 1.0.0
* @createTime: 2023-07-01 11:35
*/
public static String getStaticResource(String path, String file) {
String projectPath = System.getProperty("user.dir");
String staticResource = projectPath + "\\src\\main\\resources\\static\\template\\" + file;
return staticResource;
}
}
package com.pany.camp.email;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.IOException;
/**
*
* @description: email 发送
* @copyright: @Copyright (c) 2022
* @company: Aiocloud
* @author: pany
* @version: 1.0.0
* @createTime: 2023-07-01 8:44
*/
@Slf4j
@RestController
@RequestMapping("/v1/email")
public class EmailController {
@Resource
private IMailApp mailApp;
@GetMapping("/send")
public void send() {
FileInputStream fis = null;
try {
fis = new FileInputStream(ResourceUtils.getStaticResource("template", "email.html"));
StringBuilder sb = new StringBuilder();
int temp = 0;
while ((temp = fis.read()) != -1) {
sb.append((char) temp);
}
String registerMail = sb.toString();
mailApp.sendMimeMessge("py_world@163.com", "激流丶创作", registerMail);
} catch (Exception e) {
log.error("Failed to send verification code!cause by:", e);
} finally {
// try {
// fis.close();
// } catch (IOException e) {
// }
}
}
}
package com.pany.camp.email;
/**
*
* @description: 邮件接口
* @copyright: @Copyright (c) 2022
* @company: Aiocloud
* @author: pany
* @version: 1.0.0
* @createTime: 2023-07-01 8:48
*/
public interface IMailApp {
void sendMimeMessge(String to, String subject, String content);
}
package com.pany.camp.email;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import java.io.File;
import java.util.Map;
/**
*
* @description: 邮件业务处理
* @copyright: @Copyright (c) 2022
* @company: Aiocloud
* @author: pany
* @version: 1.0.0
* @createTime: 2023-07-01 8:47
*/
@Slf4j
@Service
public class MailAppImpl implements IMailApp {
@Resource
private JavaMailSender mailSender;
@Value("${spring.mail.username}")
private String SENDER;
/**
* 发送邮件
*
* @since 1.0.0
* @param
* @param to
* @param subject
* @param content
* @return: void
* @author: pany
* @version: 1.0.0
* @createTime: 2023-07-01 8:48
*/
@Override
public void sendMimeMessge(String to, String subject, String content) {
MimeMessage message = mailSender.createMimeMessage();
try {
// true表示需要创建一个multipart message
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(SENDER);
helper.setTo(to);
helper.setSubject(subject);
helper.setText(content, true);
mailSender.send(message);
} catch (MessagingException e) {
log.error("send email message error, cause by:", e);
}
}
}
html 代码如下:
<div>
<div style="font-family: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; line-height: 23.8px; widows: 1; width: 800px; margin: 0px auto; word-break: break-word !important;">
<div style="height: 60px; width: 800px; display: flex; align-items: center; flex-wrap: nowrap; color: rgb(255, 255, 255); border: 1px solid rgb(0, 21, 41); background: rgb(0, 21, 41); word-break: break-word !important;">
<a href="https://www.xxx.com/" style="text-decoration-line: none; word-break: break-word !important;">
<div style="display: flex; align-items: center; flex-wrap: nowrap; width: 490px; word-break: break-word !important;">
<img src="https://www.xxx.com//1_email/logo.png"
style="width: 40px; height: 40px; margin-left: 10px; word-break: break-word !important;">
<div style="margin-left: 5px; color: rgb(255, 255, 255); font-family: 宋体; font-size: 18px; font-weight: bold; word-break: break-word !important;">
爱启云科技
</div>
</div>
</a>
<div style="display: flex; align-items: center; flex-wrap: nowrap; width: 300px; word-break: break-word !important;">
<a href="https://www.xxx.com/"
style="text-decoration-line: none; word-break: break-word !important;">
<div style="width: 100px; height: 30px; line-height: 30px; border-right: 1px solid rgb(191, 191, 191); text-align: center; color: rgb(255, 255, 255); word-break: break-word !important;">
公司官网
</div>
</a><a href="https://www.xxx.com/#/solution"
style="text-decoration-line: none; word-break: break-word !important;">
<div style="width: 100px; height: 30px; line-height: 30px; border-right: 1px solid rgb(191, 191, 191); text-align: center; color: rgb(255, 255, 255); word-break: break-word !important;">
解决方案
</div>
</a><a href="http://xxx:8080/#/login"
style="text-decoration-line: none; word-break: break-word !important;">
<div style="width: 100px; height: 30px; line-height: 30px; border-right: 0px solid rgb(191, 191, 191); text-align: center; color: rgb(255, 255, 255); word-break: break-word !important;">
体验环境
</div>
</a></div>
</div>
<div style="display: flex; flex-wrap: nowrap; width: 801px; height: 720px; border-left: 1px solid rgb(238, 238, 238); word-break: break-word !important;">
<div style="width: 560px; word-break: break-word !important;">
<div style="padding: 20px; height: 408px; word-break: break-word !important;">
<div style="color: rgb(20, 20, 20); line-height: 28px; word-break: break-word !important;">
尊敬的领导您好:
</div>
<div style="color: rgb(20, 20, 20); line-height: 28px; text-indent: 2em; word-break: break-word !important;">
以下是关于我司《村(社区)两委干部管理系统》的资料,详细资料可以点击下方链接查看《村(社区)两委干部管理系统》详细材料或查看邮件附件。
</div>
<div style="display: flex; flex-wrap: nowrap; margin-top: 20px; word-break: break-word !important;">
<div style="padding: 5px 10px; border-radius: 3px; margin-right: 20px; background-color: rgba(0, 0, 0, 0.7); word-break: break-word !important;">
<a href="https://www.xxx.com/1_email/%E7%88%B1%E5%90%AF%E4%BA%91%E7%A7%91%E6%8A%80%E6%9D%91%EF%BC%88%E7%A4%BE%E5%8C%BA%EF%BC%89%E4%B8%A4%E5%A7%94%E5%B9%B2%E9%83%A8%E7%AE%A1%E7%90%86%E7%B3%BB%E7%BB%9F.pdf"
style="color: rgb(255, 255, 255); text-decoration-line: none; height: 20px; line-height: 20px; word-break: break-word !important;">点击查看详细资料</a>
</div>
<div style="padding: 5px 10px; border-radius: 3px; background-color: rgba(0, 0, 0, 0.7); word-break: break-word !important;">
<a href="http://xxx:8080/#/login"
style="color: rgb(255, 255, 255); text-decoration-line: none; height: 20px; line-height: 20px; word-break: break-word !important;">去体验(请联系销售开通账号)</a>
</div>
</div>
<div style="color: rgb(20, 20, 20); line-height: 28px; margin-top: 40px; word-break: break-word !important;">
谢谢~!
</div>
</div>
<div style="display: flex; align-items: center; flex-wrap: nowrap; height: 250px; width: 558px; border: 1px solid rgb(238, 238, 238); justify-content: center; background: rgb(238, 238, 238); word-break: break-word !important;">
<div style="word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/gzh-qrcode.jpg"
style="width: 150px; height: 150px; margin-left: 10px; word-break: break-word !important;">
<div style="text-align: center; line-height: 28px; word-break: break-word !important;">
企业官方微信公众号
</div>
</div>
<div style="word-break: break-word !important;"><img src="https://www.xxx.com/1_email/qykf.jpg"
style="width: 150px; height: 150px; margin-left: 10px; word-break: break-word !important;">
<div style="text-align: center; line-height: 28px; word-break: break-word !important;">
企业官方客服微信
</div>
</div>
</div>
</div>
<div style="width: 241px; text-align: right; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial; word-break: break-word !important;">
<div style="line-height: 40px; color: rgb(9, 109, 217); word-break: break-word !important;">我们的其他产品<span
class="Apple-converted-space"> </span><span
style="font-size: 12px; line-height: 40px; word-break: break-word !important;">(点击查看大图)</span>
</div>
<a href="https://www.xxx.com/1_email/vcms.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/vcms.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
村(社区)两委干部管理系统
</div>
</a><a href="https://www.xxx.com/1_email/di2.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/di2.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
干部测评管理系统
</div>
</a><a href="https://www.xxx.com/1_email/di3.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/di3.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
因私出国境管理系统
</div>
</a><a href="https://www.xxx.com/1_email/di4.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/di4.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
干部因私出国境审批管理系统
</div>
</a><a href="https://www.xxx.com/1_email/di5.jpg"
style="text-decoration-line: none; word-break: break-word !important;"><img
src="https://www.xxx.com/1_email/di5.jpg"
style="width: 200px; height: 100px; word-break: break-word !important;">
<div style="font-size: 12px; line-height: 28px; color: rgb(9, 109, 217); margin-left: 20px; word-break: break-word !important;">
干部研判辅助分析管理系统
</div>
</a></div>
</div>
<div style="height: 40px; width: 800px; display: flex; align-items: center; flex-wrap: nowrap; color: rgb(255, 255, 255); border: 1px solid rgb(0, 21, 41); justify-content: center; background: rgb(0, 21, 41); word-break: break-word !important;">
杭州爱启云网络科技有限公司<span style="margin-left: 40px; word-break: break-word !important;">助力城市数字化改革<span
class="Apple-converted-space"> </span><span
style="margin-left: 10px; word-break: break-word !important;"></span>数智科技赋能未来</span></div>
</div>
<br style="font-family: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; line-height: 23.8px; widows: 1; word-break: break-word !important;">
<p style="font-family: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; line-height: 23.8px; widows: 1; word-break: break-word !important;"></p>
<br style="font-family: Arial; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; line-height: 23.8px; widows: 1; word-break: break-word !important;">
</div>
html 代码我放的位置 resources/static/template/email.html,截图如下:
具体路径可以自行修改,但是 ResourceUtils 里面的路径也要做出修改。
发送的效果展示
5、如何获取邮箱授权码
登录网易邮箱 https://email.163.com/
然后点击开启,点击继续开启
按指引操作发送短信即可:
💕💕 本文由激流原创,原创不易,感谢支持
💕💕喜欢的话记得点赞收藏啊