You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flowable中Mail Service Task抛出FlowableException:连接被拒绝问题求助

问题分析与解决方案

我之前碰到过好几个类似的Flowable邮件任务连接失败的问题,你的java.net.ConnectException: Connection refused本质是Flowable引擎尝试连接SMTP邮件服务器时无法建立网络连接,核心原因要么是邮件服务器配置缺失/错误,要么是网络层面的限制。咱们一步步来排查解决:

1. 先补全Flowable的邮件服务器核心配置

Flowable的邮件服务任务本身只定义了收件人、内容等业务参数,SMTP服务器的连接信息需要在引擎全局配置里设置,你大概率是漏掉了这部分配置。

如果你用的是Spring Boot环境(修改application.properties):

# SMTP服务器地址(比如QQ邮箱是smtp.qq.com,Gmail是smtp.gmail.com)
spring.mail.host=smtp.yourmailprovider.com
# SMTP端口(普通端口25,SSL用465,TLS用587,根据服务商要求选)
spring.mail.port=587
# 你的发件邮箱账号
spring.mail.username=your-sender-email@domain.com
# 邮箱授权码(注意:很多服务商需要用授权码而非登录密码,比如QQ、Gmail)
spring.mail.password=your-authorization-code
# 启用TLS加密(大部分服务商要求)
spring.mail.properties.mail.smtp.starttls.enable=true
# 开启SMTP身份验证
spring.mail.properties.mail.smtp.auth=true

如果你用的是独立Flowable引擎(修改flowable.cfg.xml):

<bean id="processEngineConfiguration" class="org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration">
    <!-- 其他引擎配置(数据源、事务等) -->
    <property name="mailServerHost" value="smtp.yourmailprovider.com" />
    <property name="mailServerPort" value="587" />
    <property name="mailServerUsername" value="your-sender-email@domain.com" />
    <property name="mailServerPassword" value="your-authorization-code" />
    <property name="mailServerUseTLS" value="true" />
</bean>

2. 验证SMTP服务器的网络可达性

配置完后,先在部署Flowable的机器上测试能不能连到目标SMTP服务器:

# 用telnet测试连接
telnet smtp.yourmailprovider.com 587
# 或者用nc命令(更直观)
nc -zv smtp.yourmailprovider.com 587

如果连接失败,说明:

  • 你的机器被防火墙/代理挡住了,无法访问该SMTP端口
  • 你填的SMTP地址或端口有误(比如很多服务商已经禁用了25端口)

3. 排查邮件服务商的特殊限制

很多主流邮箱服务商(Gmail、QQ、Outlook)对第三方客户端发邮件有额外限制:

  • 需要在邮箱后台开启“POP3/SMTP服务”或“IMAP/SMTP服务”
  • 必须使用授权码而非登录密码(尤其是国内邮箱)
  • Gmail还需要开启“不太安全的应用访问”或者用App密码(针对两步验证账号)

4. 先脱离Flowable测试邮件发送

如果上面的配置和网络都没问题,建议先写个简单的Java邮件发送程序,直接用JavaMail API测试,排除Flowable引擎的问题:

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class TestMailSend {
    public static void main(String[] args) {
        String to = "testemail@some.com";
        String from = "your-sender-email@domain.com";
        String host = "smtp.yourmailprovider.com";

        Properties props = new Properties();
        props.setProperty("mail.smtp.host", host);
        props.setProperty("mail.smtp.port", "587");
        props.setProperty("mail.smtp.auth", "true");
        props.setProperty("mail.smtp.starttls.enable", "true");

        Session session = Session.getInstance(props, new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(from, "your-authorization-code");
            }
        });

        try {
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject("Test Mail from Java");
            message.setText("This is a test to verify SMTP connection");

            Transport.send(message);
            System.out.println("Mail sent successfully!");
        } catch (MessagingException e) {
            e.printStackTrace();
        }
    }
}

如果这个程序能正常发邮件,再回到Flowable里检查配置是否和测试代码一致,大概率就能解决问题了。


内容的提问来源于stack exchange,提问作者Sri9911

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:38:02