• azkaban邮箱配置


    ① 环境准备: azkaban web端和server端能正常启动,并且正常登录,安装参考上篇
            azkaban安装(Linux环境)_江湖峰哥的博客-CSDN博客

    ② 邮箱配置主要配置邮箱发送端,并且只需要配置web端即可

    ③ 注意踩坑,azkaban3.9.0.0这个版本无法使用smtps协议发送邮件,源码如下:
     

    1. public class JavaxMailSender {
    2. public static final String PROTOCOL = "smtp";
    3. private final Session session;
    4. private final SMTPTransport t;
    5. public JavaxMailSender(final Properties props)
    6. throws NoSuchProviderException {
    7. this.session = Session.getInstance(props, null);
    8. this.t = (SMTPTransport) this.session.getTransport(PROTOCOL);
    9. }
    10. ......

    最终调用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通,但是邮件始终发送不出去,还有一点注意踩坑,源码如下:
     

    1. public class EmailMessageCreator {
    2. public static final int DEFAULT_SMTP_PORT = 25;
    3. private final String mailHost;
    4. private final int mailPort;
    5. private final String mailUser;
    6. private final String mailPassword;
    7. private final String mailSender;
    8. private final String tls;
    9. private final boolean usesAuth;
    10. @Inject
    11. public EmailMessageCreator(final Props props) {
    12. this.mailHost = props.getString("mail.host", "localhost");
    13. this.mailPort = props.getInt("mail.port", DEFAULT_SMTP_PORT);
    14. this.mailUser = props.getString("mail.user", "");
    15. this.mailPassword = props.getString("mail.password", "");
    16. this.mailSender = props.getString("mail.sender", "");
    17. this.tls = props.getString("mail.tls", "false");
    18. this.usesAuth = props.getBoolean("mail.useAuth", true);
    19. }

    邮件配置参数通过EmailMessageCreator注入并向后传递,但是该类中并没有打算接收protocol的属性配置,所以即使配置了这里也获取不到,所以需要修改源代码两处:
     

    1. 伪代码:
    2. public class EmailMessageCreator {
    3. public static final int DEFAULT_SMTP_PORT = 25;
    4. private final String mailHost;
    5. private final int mailPort;
    6. private final String mailUser;
    7. private final String mailPassword;
    8. private final String mailSender;
    9. private final String protocol; // 增加protocol属性
    10. private final String tls;
    11. private final boolean usesAuth;
    12. @Inject
    13. public EmailMessageCreator(final Props props) {
    14. this.mailHost = props.getString("mail.host", "localhost");
    15. this.mailPort = props.getInt("mail.port", DEFAULT_SMTP_PORT);
    16. this.mailUser = props.getString("mail.user", "");
    17. this.mailPassword = props.getString("mail.password", "");
    18. this.protocol = props.getString("mail.transport.protocol", "smtp"); // 通过配置文件注入属性,key为mail.transport.protocol,默认值为smtp
    19. this.mailSender = props.getString("mail.sender", "");
    20. this.tls = props.getString("mail.tls", "false");
    21. this.usesAuth = props.getBoolean("mail.useAuth", true);
    22. }
    23. ......
    24. }
    25. 伪代码:
    26. public class JavaxMailSender {
    27. public static final String PROTOCOL = "smtp";
    28. private final Session session;
    29. private final Transport t; // 用顶级父类接收
    30. public JavaxMailSender(final Properties props)
    31. throws NoSuchProviderException {
    32. this.session = Session.getInstance(props, null);
    33. this.t = this.session.getTransport(props.getProperty("mail.transport.protocol",PROTOCOL));
    34. // 通过传入的参数获取要返回的实例,没传入就使用默认值
    35. }

    ④ 参考上篇的安装,重新编译源码

    ⑤ 添加配置文件

    1. # mail settings 这里配置的是邮件发送方属性
    2. mail.transport.protocol=smtps
    3. mail.sender=123456@163.com
    4. mail.host=smtp.163.com
    5. mail.port=465 #可以不配,smtps协议默认端口465
    6. mail.user=123456@163.com
    7. mail.password=abcdef #这里是不同邮箱官方给的授权码,不是邮箱登录密码,怎么获取自己查资料
    8. mail.useAuth=true
    9. #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, NULL

    linux[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.namedCurves

    linux平台jdk将TLSv1, TLSv1.1加密算法禁用了,所以导致使用smtps协议无法正常使用,解决办法将TLSv1, TLSv1.1这两种算法干掉,表示启用这两种算法

    ⑦ source一下环境变量,重新启动azkaban服务,接下来去测试邮件服务,不出意外就能成功了!祝您好运!!!!

  • 相关阅读:
    如何使用Docker安装Kibana
    10【桥接设计模式】
    华为面试应该怎么准备?
    8K直播如何多路推流到抖音、微博、视频号、B站等平台
    Vue框架总结(二、Vue计算属性与监听属性)
    第八章 接口
    Aroid问题笔记 - ViewPager嵌套RecyclerView,降低ViewPager灵敏度
    递推算法 C++
    Golang Struct 继承的深入讨论和细节
    又一个Java面试神器!!!
  • 原文地址:https://blog.csdn.net/querydata_boke/article/details/125432151