① 环境准备: azkaban web端和server端能正常启动,并且正常登录,安装参考上篇
azkaban安装(Linux环境)_江湖峰哥的博客-CSDN博客② 邮箱配置主要配置邮箱发送端,并且只需要配置web端即可
③ 注意踩坑,azkaban3.9.0.0这个版本无法使用smtps协议发送邮件,源码如下:
public class JavaxMailSender { public static final String PROTOCOL = "smtp"; private final Session session; private final SMTPTransport t; public JavaxMailSender(final Properties props) throws NoSuchProviderException { this.session = Session.getInstance(props, null); this.t = (SMTPTransport) this.session.getTransport(PROTOCOL); } ......最终调用azkaban-3.90.0/azkaban-common/src/main/java/azkaban/utils/JavaxMailSender类中下SMTPTransport的当前实例去建立连接,发送消息,而源码
this.t = (SMTPTransport) this.session.getTransport(PROTOCOL);这句代码看得我一脸懵逼,框架默认注入了pop3s,pop3,smtps,imaps不同协议的不同Provider实例,通过传入不同的protocol返回不同的实现,源码是将实例缓存在hashtable中,因为这里写死了protocol为smtp,所以无论怎么配置都只能使用25端口通过smtp协议发送邮件,而一般的云服务器都将25端口禁用掉了,这里做过测试,阿里云主机,25端口虽然能telnet通,但是邮件始终发送不出去,还有一点注意踩坑,源码如下:
public class EmailMessageCreator { public static final int DEFAULT_SMTP_PORT = 25; private final String mailHost; private final int mailPort; private final String mailUser; private final String mailPassword; private final String mailSender; private final String tls; private final boolean usesAuth; @Inject public EmailMessageCreator(final Props props) { this.mailHost = props.getString("mail.host", "localhost"); this.mailPort = props.getInt("mail.port", DEFAULT_SMTP_PORT); this.mailUser = props.getString("mail.user", ""); this.mailPassword = props.getString("mail.password", ""); this.mailSender = props.getString("mail.sender", ""); this.tls = props.getString("mail.tls", "false"); this.usesAuth = props.getBoolean("mail.useAuth", true); }邮件配置参数通过EmailMessageCreator注入并向后传递,但是该类中并没有打算接收protocol的属性配置,所以即使配置了这里也获取不到,所以需要修改源代码两处:
伪代码: public class EmailMessageCreator { public static final int DEFAULT_SMTP_PORT = 25; private final String mailHost; private final int mailPort; private final String mailUser; private final String mailPassword; private final String mailSender; private final String protocol; // 增加protocol属性 private final String tls; private final boolean usesAuth; @Inject public EmailMessageCreator(final Props props) { this.mailHost = props.getString("mail.host", "localhost"); this.mailPort = props.getInt("mail.port", DEFAULT_SMTP_PORT); this.mailUser = props.getString("mail.user", ""); this.mailPassword = props.getString("mail.password", ""); this.protocol = props.getString("mail.transport.protocol", "smtp"); // 通过配置文件注入属性,key为mail.transport.protocol,默认值为smtp this.mailSender = props.getString("mail.sender", ""); this.tls = props.getString("mail.tls", "false"); this.usesAuth = props.getBoolean("mail.useAuth", true); } ...... } 伪代码: public class JavaxMailSender { public static final String PROTOCOL = "smtp"; private final Session session; private final Transport t; // 用顶级父类接收 public JavaxMailSender(final Properties props) throws NoSuchProviderException { this.session = Session.getInstance(props, null); this.t = this.session.getTransport(props.getProperty("mail.transport.protocol",PROTOCOL)); // 通过传入的参数获取要返回的实例,没传入就使用默认值 }④ 参考上篇的安装,重新编译源码
⑤ 添加配置文件
# mail settings 这里配置的是邮件发送方属性 mail.transport.protocol=smtps mail.sender=123456@163.com mail.host=smtp.163.com mail.port=465 #可以不配,smtps协议默认端口465 mail.user=123456@163.com mail.password=abcdef #这里是不同邮箱官方给的授权码,不是邮箱登录密码,怎么获取自己查资料 mail.useAuth=true #mail.tls=true //这里要么不配置,要么为false,配置为true,邮件发送不出去⑥ 以为万事大吉,其实还没有,你还有可能遇到下面的坑,跟jdk版本和平台有关
windows[jdk1.8]: openjdk\jre\lib\security\java.security
jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, \
EC keySize < 224, 3DES_EDE_CBC, anon, NULLlinux[jdk1.8]: jdk1.8.0_301/jre/lib/security/java.security
jdk.tls.disabledAlgorithms=SSLv3, TLSv1, TLSv1.1, RC4, DES, MD5withRSA, \
DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL, \
include jdk.disabled.namedCurveslinux平台jdk将TLSv1, TLSv1.1加密算法禁用了,所以导致使用smtps协议无法正常使用,解决办法将TLSv1, TLSv1.1这两种算法干掉,表示启用这两种算法
⑦ source一下环境变量,重新启动azkaban服务,接下来去测试邮件服务,不出意外就能成功了!祝您好运!!!!