使用nettemail-封装一个发送邮件类-通用

使用nette/mail 封装一个发送邮件类 (通用)使用到的包 composer require nette/mail封装Mail体<?php/*** Created by PhpStorm.* User: 邓尘锋* Date: 19-7-5* Time: 上午11:57* surest.cn*/namespace app\common\server;use Nette\InvalidArgumentException;use Nette\Mail\Message;class Mail extends Message{ public $config; // [String] e-mail protected $from; // [Array] e-mail list protected $to; protected $title; protected $body; public function __construct($to) { $host = config('email.username'); $this->setFrom("{$host}", "D88科技") ->setHeader("name", $host); if ( is_array($to) ) { foreach ($to as $email) { $this->addTo($email); } } else { $this->addTo($to); } } public function from($from=null) { if ( !$from ) { throw new InvalidArgumentException("邮件发送地址不能为空!"); } $this->setFrom($from); return $this; } public static function to($to=null) { if ( !$to ) { throw new InvalidArgumentException("邮件接收地址不能为空!"); } return new Mail($to); } public function title($title=null) { if ( !$title ) { throw new InvalidArgumentException("邮件标题不能为空!"); } $this->setSubject($title); return $this; } public function content($content=null) { if ( !$content ) { throw new InvalidArgumentException("邮件内容不能为空!"); } $this->setHTMLBody($content); return $this; }}封装Mailer发送类 <?php /** * Created by PhpStorm. * User: chenf * Date: 19-7-16 * Time: 下午3:35 */ namespace app\common\server; use Nette\Mail\Message; use Nette\Mail\SmtpMailer; /** * * 使用: * $mail = Mail::to($emails)->title("错误预警")->content($html); * Mailer::setMailer()->send($mail); * * Class Mailer * @package app\common\server */ class Mailer { /** * 实例化一个Mailer类 * @return SmtpMailer */ public static function setMailer() { # 这里的配置读取的是config配置 $mailer = new SmtpMailer([ 'host' => config('email.host'), 'username' => config('email.username'), 'password' => config('email.password'), 'secure' => config('email.secure') ]); return $mailer; } /** * 发送 * @param Message $mail */ public function send(Message $mail) { $this->send($mail); } }配置'host' => 'smtp.exmail.qq.com', // 用的是qq的smtp服务器'username' => 'username', 'password' => 'password', 'secure' => 'ssl' // ssl 是 445 端口, 如不设置, 默认端口是 22 , 可参见源码使用// $emails 是一个数组// Mail Message 体$mail = Mail::to($emails)->title("错误预警")->content($html);// 发送Mailer::setMailer()->send($mail);告知如果直接使用如上方法, 采用的是同步发送的机制, 如果需要采用异步队列进行发送邮件, 我提供如下解决思路 ...

July 16, 2019 · 2 min · jiezi

SpringBoot 2.X Kotlin系列之JavaMailSender发送邮件

在很多服务中我经常需要用到发送邮件功能,所幸的是SpringBoot可以快速使用的框架spring-boot-starter-mail,只要引入改框架我们可以快速的完成发送邮件功能。引入mailJar<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-mail</artifactId></dependency>获取邮件发送服务器配置在国内用的最多的就是QQ邮件和网易163邮件,这里会简单讲解获取两家服务商的发送邮件配置。QQ邮箱等录QQ邮箱,点击设置然后选择账户在下方可以看到POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务,然后我们需要把smtp服务开启,开启成功后会得到一个秘钥。如图所示:开启成功需要在application.properties配置文件中加入相应的配置,以下信息部分需要替换为自己的信息,教程结束下面的账号就会被停用spring.mail.host=smtp.qq.comspring.mail.username=6928700@qq.com # 替换为自己的QQ邮箱号spring.mail.password=owqpkjmqiasnbigc # 替换为自己的秘钥或授权码spring.mail.port=465spring.mail.properties.mail.smtp.auth=truespring.mail.properties.mail.smtp.starttls.enable=truespring.mail.properties.mail.smtp.starttls.required=true# sender email.sender=6928700@qq.com # 替换为自己的QQ邮箱号163邮箱登录账户然后在设置找到POP3/SMTP/IMAP选项,然后开启smtp服务,具体操作如下图所示,然后修改对应的配置文件spring.mail.host=smtp.163.comspring.mail.username=xmsjgzs@163.com # 替换为自己的163邮箱号spring.mail.password=owqpkj163MC # 替换为自己的授权码spring.mail.port=465spring.mail.properties.mail.smtp.auth=truespring.mail.properties.mail.smtp.starttls.enable=truespring.mail.properties.mail.smtp.starttls.required=true# sender email.sender=xmsjgzs@163.com # 替换为自己的163邮箱号实现简单发送邮件这里发送邮件我们主要用到的是JavaMailSender对象,发送简单邮件主要是发送字符串内容,复杂的邮件我们可能会添加附件或者是发送HTML格式的邮件,我们先测试简单的发送,代码如下:override fun sendSimple(receiver: String, title: String, content: String) { logger.info(“发送简单邮件服务”) val message = mailSender.createMimeMessage() val helper = MimeMessageHelper(message, true) helper.setFrom(sender) helper.setTo(receiver) helper.setSubject(title) helper.setText(content) mailSender.send(message)}测试代码@RunWith(SpringJUnit4ClassRunner::class)@SpringBootTestclass MailServiceImplTest { @Autowired lateinit var mailService: MailService @Test fun sendSimple() { mailService.sendSimple(“xmsjgzs@163.com”, “Hello Kotlin Mail”, “SpringBoot Kotlin 专栏学习之JavaMailSender发送邮件”) }}检查邮件是否收到发送的内容发送模板邮件我们这里用的HTML模板引擎是thymeleaf,大家需要引入一下spring-boot-starter-thymeleaf<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId></dependency>有个地方需要注意,SpringBoot项目默认静态资源都是放在resources/templates目录下,所以我们编写的HTML模板就需要放在该目录下,具体内容如下:<!DOCTYPE html><html lang=“en” xmlns=“http://www.w3.org/1999/xhtml" xmlns:th=“http://www.thymeleaf.org”><head> <meta charset=“UTF-8”> <title th:text="${title}">Title</title></head><body> <h1 th:text="${name}">Demo</h1> <h1 th:text="${phone}">xxx</h1></body></html>发送模板邮件主要实现代码override fun sendMail(receiver: String, title: String, o: Any, templateName: String) { logger.info(“开始发送邮件服务,To:{}”, receiver) val message = mailSender.createMimeMessage() val helper = MimeMessageHelper(message, true) helper.setFrom(sender) helper.setTo(receiver) helper.setSubject(title) val context = Context() context.setVariable(“title”, title) /* * 设置动态数据,这里不建议强转,具体业务需求传入具体的对象 / context.setVariables(o as MutableMap<String, Any>?) / * 读取取模板html代码并赋值 / val content = templateEngine.process(templateName, context) helper.setText(content, true) mailSender.send(message) logger.info(“邮件发送结束”)}测试代码@Testfun sendMail() { val model = HashMap<String, Any>() model[“name”] = “Tom” model[“phone”] = “69288888” mailService.sendMail(“xmsjgzs@163.com”, “Kotlin Template Mail”, model, “mail”)}查看邮件我们可以看到如下内容:邮件添加附件附件的添加也是非常容易的,我需要先把发送的附件放在resources/templates目录下,然后在MimeMessageHelper对象中设置相应的属性即可,如下所示:helper.addAttachment(“test.txt”, FileSystemResource(File(“test.txt”)))完整的代码package io.intodream.kotlin06.service.implimport io.intodream.kotlin06.service.MailServiceimport org.slf4j.Loggerimport org.slf4j.LoggerFactoryimport org.springframework.beans.factory.annotation.Autowiredimport org.springframework.beans.factory.annotation.Valueimport org.springframework.core.io.FileSystemResourceimport org.springframework.mail.javamail.JavaMailSenderimport org.springframework.mail.javamail.MimeMessageHelperimport org.springframework.stereotype.Serviceimport org.thymeleaf.TemplateEngineimport org.thymeleaf.context.Contextimport java.io.File/* * {描述} * * @author yangxianxi@gogpay.cn * @date 2019/4/8 19:19 * /@Serviceclass MailServiceImpl @Autowired constructor(private var mailSender: JavaMailSender, private var templateEngine: TemplateEngine) : MailService{ val logger : Logger = LoggerFactory.getLogger(MailServiceImpl::class.java) @Value(”${email.sender}") val sender: String = “6928700@qq.com” override fun sendSimple(receiver: String, title: String, content: String) { logger.info(“发送简单邮件服务”) val message = mailSender.createMimeMessage() val helper = MimeMessageHelper(message, true) helper.setFrom(sender) helper.setTo(receiver) helper.setSubject(title) helper.setText(content) mailSender.send(message) } override fun sendMail(receiver: String, title: String, o: Any, templateName: String) { logger.info(“开始发送邮件服务,To:{}”, receiver) val message = mailSender.createMimeMessage() val helper = MimeMessageHelper(message, true) helper.setFrom(sender) helper.setTo(receiver) helper.setSubject(title) val context = Context() context.setVariable(“title”, title) / * 设置动态数据,这里不建议强转,具体业务需求传入具体的对象 / context.setVariables(o as MutableMap<String, Any>?) / * 添加附件 / helper.addAttachment(“test.txt”, FileSystemResource(File(“test.txt”))) / * 读取取模板html代码并赋值 / val content = templateEngine.process(templateName, context) helper.setText(content, true) mailSender.send(message) logger.info(“邮件发送结束”) }}测试代码package io.intodream.kotlin06.service.implimport io.intodream.kotlin06.service.MailServiceimport org.junit.Testimport org.junit.runner.RunWithimport org.springframework.beans.factory.annotation.Autowiredimport org.springframework.boot.test.context.SpringBootTestimport org.springframework.test.context.junit4.SpringJUnit4ClassRunner/* * {描述} * * @author yangxianxi@gogpay.cn * @date 2019/4/9 18:38 */@RunWith(SpringJUnit4ClassRunner::class)@SpringBootTestclass MailServiceImplTest { @Autowired lateinit var mailService: MailService @Test fun sendSimple() { mailService.sendSimple(“xmsjgzs@163.com”, “Hello Kotlin Mail”, “SpringBoot Kotlin 专栏学习之JavaMailSender发送邮件”) } @Test fun sendMail() { val model = HashMap<String, Any>() model[“name”] = “Tom” model[“phone”] = “69288888” mailService.sendMail(“xmsjgzs@163.com”, “Kotlin Template Mail”, model, “mail”) }}关于Kotlin使用JavaMailSender发送邮件的介绍就到此结束了,如果大家觉得教程有用麻烦点一下赞,如果有错误的地方欢迎指出。 ...

April 16, 2019 · 2 min · jiezi

Linux 发送邮件的命令行应用

发送邮件有超多种方法,但是接收邮件就要麻烦很多。所以这里先只讲发送邮件先说明下:不管是什么邮件客户端,都是可以直接发邮件的。但是,因为默认的话,发件人是很随便地设置成你本机地名字。并且100%会被邮箱当成垃圾邮件处理。如果你去垃圾箱里找,还是可以看到的。这就是为什么,我们还是需要配置它,让它登录某个邮箱来使用它的身份发邮件了,比如gmail邮箱或阿里云邮箱。(国内的163和qq邮箱都已经屏蔽第三方客户端登录了)另注:为什么如今这么电子技术这么发达的年代,命令行邮件终端相关的应用和文章还这么少几乎都是很多年前的?我想是因为:python等都已经能很好很方便支持发邮件了,没必要折腾命令行版本。事实上,试过就知道:为什么这些客户端会被抛弃了。。。请看下面我入的坑:Mail注:Mail的配置相当麻烦,网上找文章也寥寥无几,有也都是十几年前的东西。所以建议放弃,使用更先进的客户端。MuttMutt是Linux邮箱客户端榜上有名的利器了。先不说什么界面操作之类的,因为我们用命令行的邮箱客户端都是用来自动化的,不想用什么界面。参考:Linux使用mutt发送邮件安装其中mutt是软件本身,msmtp是用来帮助发件的工具。# Linux$ sudo apt-get install mutt msmtp# 或Mac$ brew install mutt msmtp配置你需要配置两个文件,一个是~/.muttrc用来配置Mutt本身,一个是~/.msmtprc用来配置发件人的,需要写入密码一类的。参考:Linux下使用mutt,msmtp发信配置~/.msmtprc:account Aliyunhost smtp.aliyun.comfrom jason@aliyun.comauth loginuser jason@aliyun.compassword abcde123123123account default : Aliyunlogfile /.msmtp.log然后必须修改/.msmtprc文件的权限,否则程序无法读取,发邮件时会报错。修改如下:chmod 600 /.msmtprc配置/.muttrc:set sendmail="/usr/bin/msmtp"set use_from=yesset realname=“Jason"set from=“Jason@aliyun.com"set envelope_from=yesset editor=“vim -nw"注意:第一条set sendmail中的位置不一定是这样的,在Mac和Linux上都会不同,所以需要用which msmtp来找到它的真实位置,再填进去。关于配置的解释可以看这里:发送邮件命令格式注意:收件人的地址前一定要明确指定参数名–,如下所示。否则无法正确发送附件。# 常用格式如下 -s “标题” -c 抄送 -a 附件$ echo “HELLO WORLD” | mutt -s “TITLE” – RECIPIENT@gmail.com# 发送HTML格式漂亮的邮件$ mutt – RECIPIENT@gmail.com -e ‘set content_type=“text/html”’ -s “TITLE” < out.html# 发送给多人,抄送,添加附件$ echo “hello” | mutt -s “TITLE” aaa@gmail.com, bbb@gmail.com -c ccc@gmail.com -a /home/pi/pic.jpg address=“RECIPIENT@gmail.com”# 发送邮件时设置邮件的文本类型为:html格式,邮件的等级为:重要$ echo $content | mutt -s “${subject}” -e ‘set content_type=“text/html”’ -e ‘send-hook . “my_hdr X-Priority: 1”’ $address语法:参数:Mutt发送HTML漂亮富文本邮件默认语法是:$ mutt – RECIPIENT@gmail.com -e ‘set content_type=“text/html”’ -s “TITLE” < out.html但是,值得注意的是,语法虽然简单,可一旦你本机的mutt版本不对,邮件将无法显示出正确的格式,而只是无尽的html源代码。通过mutt -v可以看到,发送出显示正常的邮件的mutt版本是在树莓派上安装的Mutt 1.5.23 (2014-03-12)。而不成功的是在Mac上的Mutt 1.9.5 (2018-04-13),反而是最新的版本!邮箱配置阿里云邮箱163邮箱新浪邮箱- 新浪@sina.com邮箱,接收服务器地址为:pop.sina.com或pop3.sina.com,发送服务器地址为:smtp.sina.com- 新浪@sina.cn邮箱,接收服务器地址为:pop.sina.cn或pop3.sina.cn,发送服务器地址为:smtp.sina.cn- 端口号设置:POP协议:pop端口:110、smtp端口:25 IMAP协议:IMAP 端口:143、smtp端口:25- 加密设置:pop是995、imap的是993smtp是587或465,如465不能正常使用,可以更换587试试,但不同的国家有可能只支持一个端口(并非所有客户端都支持加密码) 。 ...

January 24, 2019 · 1 min · jiezi

java通过smtp服务 给指定邮箱发送邮件含附件

用程序发邮件首先需要一个smtp服务器,虽然说网上也有自建服务器的教程,但是由于工程量大,还要兼容各大邮箱厂商,有可能发送失败或被归为垃圾邮件。所以不推荐自建smtp服务器实现。推荐是有2种方法来实现 第三方邮箱发邮件1、买类似阿里云的smtp资源包(阿里云 1000条 / 2元)2、申请一个腾讯、网易163的邮箱,开通smtp服务端口,借由他们的服务器来转发。(其中部分第三方邮箱可以实现用自己的域名来接发邮件,例如service@baidu.com)本文中介绍的是第二种方法,用腾讯企业邮箱为例参考借鉴的大神的原文地址:https://www.cnblogs.com/LUA123/p/5575134.html这里重点只说明一下,腾讯企业邮箱 + javamail 来实现发邮件,代码的部分。其他邮箱,例如个人的qq邮箱 163邮箱也可以用这个方法实现,申请和设置方法借鉴百度吧补充一下!腾讯企业邮箱和qq邮箱方法有几个不同,我在末尾加了qq邮箱的方案正文开始先说腾讯企业邮箱maven<dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.7</version></dependency>另外我用到了一个 StringUtils.isNotBlank() 方法 可以选择引入以下maven依赖,也可以改写成 xxx != null && !"".equals(xxx) 等价的代码<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.7</version></dependency>java 工具类需要把 用户名、密码、发件人别名 等参数填成你自己申请的package com.gemini.common.utils; import com.sun.mail.util.MailSSLSocketFactory;import org.apache.commons.lang.StringUtils; import java.io.IOException;import java.io.UnsupportedEncodingException;import java.security.GeneralSecurityException;import java.util.Date;import java.util.Properties; import javax.mail.Authenticator;import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Multipart;import javax.mail.PasswordAuthentication;import javax.mail.Session;import javax.mail.Transport;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeBodyPart;import javax.mail.internet.MimeMessage;import javax.mail.internet.MimeMultipart; public class EmailUtils { // 腾讯企业邮箱 也可以换成别家的 private static final String protocol = “smtp”;// 协议 private static final String host = “smtp.exmail.qq.com”;// 地址 private static final String port = “465”;// 端口 private static final String account = “用户名”;// 用户名 private static final String pass = “密码”;// 密码 private static final String personal = “发件人别名(选填)”;// 发件人别名,不需要设为空串或null // 权限认证 static class MyAuthenricator extends Authenticator { String u = null; String p = null; public MyAuthenricator(String u, String p) { this.u = u; this.p = p; } @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(u, p); } } /** * 发送邮件工具方法 * * @param recipients 收件人 * @param subject 主题 * @param content 内容 * @param fileStr 附件路径 * @return true/false 发送成功 */ public static boolean sendEmail(String recipients, String subject, String content, String fileStr) { Properties prop = new Properties(); //协议 prop.setProperty(“mail.transport.protocol”, protocol); //服务器 prop.setProperty(“mail.smtp.host”, host); //端口 prop.setProperty(“mail.smtp.port”, port); //使用smtp身份验证 prop.setProperty(“mail.smtp.auth”, “true”); //使用SSL,企业邮箱必需! //开启安全协议 MailSSLSocketFactory mailSSLSocketFactory = null; try { mailSSLSocketFactory = new MailSSLSocketFactory(); mailSSLSocketFactory.setTrustAllHosts(true); } catch (GeneralSecurityException e1) { e1.printStackTrace(); } prop.put(“mail.smtp.ssl.enable”, “true”); prop.put(“mail.smtp.ssl.socketFactory”, mailSSLSocketFactory); Session session = Session.getDefaultInstance(prop, new MyAuthenricator(account, pass)); session.setDebug(true); MimeMessage mimeMessage = new MimeMessage(session); try { //发件人 if (StringUtils.isNotBlank(personal)) mimeMessage.setFrom(new InternetAddress(account, personal));//可以设置发件人的别名 else mimeMessage.setFrom(new InternetAddress(account));//如果不需要就省略 //收件人 mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(recipients)); //主题 mimeMessage.setSubject(subject); //时间 mimeMessage.setSentDate(new Date()); //容器类,可以包含多个MimeBodyPart对象 Multipart mp = new MimeMultipart(); //MimeBodyPart可以包装文本,图片,附件 MimeBodyPart body = new MimeBodyPart(); //HTML正文 body.setContent(content, “text/html; charset=UTF-8”); mp.addBodyPart(body); //添加图片&附件 if(StringUtils.isNotBlank(fileStr)){ body = new MimeBodyPart(); body.attachFile(fileStr); mp.addBodyPart(body); } //设置邮件内容 mimeMessage.setContent(mp); //仅仅发送文本 //mimeMessage.setText(content); mimeMessage.saveChanges(); Transport.send(mimeMessage); // 发送成功 return true; } catch (MessagingException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; } public static void main(String[] args) { sendEmail(“你的邮箱地址”,“test”,“test”,null); }}关于上述方案,适用于一般的邮箱申请(腾讯企业邮箱、网易邮箱),但不适用于qq邮箱,原因是qq邮箱目前只接受授权码方案登录,官方的解释是“温馨提示:在第三方登录QQ邮箱,可能存在邮件泄露风险,甚至危害Apple ID安全,建议使用QQ邮箱手机版登录。 继续获取授权码登录第三方客户端邮箱 。”使用上述方法登录qq邮箱会遇到报错javax.mail.AuthenticationFailedException: 535 Error: ÇëʹÓÃÊÚȨÂëµÇ¼¡£ÏêÇéÇë¿´: http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256如图意思就是不支持直接用默认密码登录,必须去申请一个授权码作为密码登录其实流程和工具类都一样就重点说 2个不一样的地方1、密码不是你的邮箱密码了,而是授权码。获取方式 [登录邮箱] - [设置] - [账户] ,然后如下图找到POP3/SMTP服务的下面,有一句温馨提示 先点 [生成授权码] ,再根据提示获取到授权码。授权码就是javamail里的password2、host不同腾讯企业邮箱的host是private static final String host = “smtp.exmail.qq.com”;// 地址普通qq邮箱的host是private static final String host = “smtp.qq.com”;// 地址修改这两个地方即可适用于个人普通的qq邮箱最终效果如下另外本文也发布在了我的个人博客: https://zzzmh.cn/single?id=49 ...

January 17, 2019 · 2 min · jiezi

在gmail中使用邮件模板功能

写在前面gmail没有邮件模板的功能,虽然有一个类似的功能可以达到模板的效果,但是在gmail的帮助文档里面并没有提及,所以才有了这篇文章。问题复现工作中经常有些格式固定,内容相似的邮件是需要重复发送的,比如日报、周报之类的。对于这种情况我们一般会很容易想到用邮件模板来避免复制粘贴,但是对于gmail来说,很遗憾不支持邮件模板功能,那怎么办呢?别急,方法总是有的。问题解决普通方案在gmail中虽然没有邮件模板功能,但是有一个与之类似的功能,叫:预设回复。这个功能的描述是这样的:预设回复(模板)使用写邮件工具栏中的按钮存储常用邮件以创建回复模板。您也可以使用过滤器自动发送回复模板。恩,如此看来,这个功能可以作为邮件模板来使用,那我们来看看怎么用。step 0 开启预设回复(模板)功能设置 -> 高级 -> 预设回复(模板)-> 启用step 1 创建模板写邮件 -> 更多选项(右下角的三个点) -> 预设的电子邮件回复 -> 新建预设的电子邮件回复(保存项下的) -> 输入模板名step 2 使用模板写邮件 -> 更多选项(右下角的三个点) -> 预设的电子邮件回复 -> 点击模板名字(插入项下的)step 3 管理模板gamil的模板管理很不友好,没有专门的界面管理模板,只有在预设的电子邮件回复选项下有插入、保存、删除三个功能。插入就是往邮件体内应用模板保存可以新建模板也可以覆盖原有的模板删除可以删除模板(废话)如此,问题得到解决。但是我们还有另一种解决方案。极客方案问题的解决方法往往不止一个,我们还可以辅以chrome插件来解决这个问题。最终可以实现类似在sublime中插入code snippet那么方便的操作:按个快捷键就能插入模板,甚至是带有变量的模板。我们用到的插件叫做:Gorgias Templates 使用文档插件的基本用法就不多说了,这个上手很容易,值得一提的是他对邮件模板的拓展和模板变量的使用。邮件模板拓展在普通方案中我们的邮件模板只是把邮件体和主题做成了模板,并不包含收件人信息,而通过这个插件,我们可以把邮件主题、收件人甚至抄送、密送都在模板中设置好,这点不可谓不方便。方法是在新建模板的时候点击Show more fields来展开更多项,进行配置。模板变量模板变量,有点模板引擎的感觉,通过模板变量可以使我们的模板(包括收件人、主题等)更加灵活简单。目前支持的变量有:邮件主题(subject)收件人(to)发件人(from)抄送(cc)密送(bcc)日期(date)日期格式化支持momentjs传参随机项 (choice)邮件域名(domain)通过这插件我们基本可以实现这样的一个模板:收件人固定主题带有动态日期邮件内容固定而整个过程中我们要做的就是配好模板,在使用地方按下快捷键,操作就是这么流畅。总结极客方案虽酷,但是也不是没有缺点,我们来对比一下两种方案。方案邮件体 + 主题模板收件人 + 抄送 + 密送模板变量模板同步普通方案支持不支持不支持支持极客方案支持支持支持不支持所以,其中利弊各自权衡吧。[完]

January 16, 2019 · 1 min · jiezi