gpt4 book ai didi

java - 如何在 Mule ESB 上发送电子邮件

转载 作者:行者123 更新时间:2023-12-02 04:55:49 26 4
gpt4 key购买 nike

我正在尝试发送一封包含示例项目的电子邮件。我尝试做的是一个示例书店,用户收到一个表格,其中填写了订单(姓名、nif、电子邮件、书籍...)。我想将之前完成的订单信息发送到该电子邮件地址。当我尝试这样做时,它显示下一个错误:

Root Exception stack trace:
java.lang.IllegalArgumentException: The required object/property "Email address" is null
at org.mule.transport.email.MailUtils.stringToInternetAddresses(MailUtils.java:93)
at org.mule.transport.email.transformers.StringToEmailMessage.transformMessage(StringToEmailMessage.java:113)
at org.mule.transport.email.transformers.ObjectToMimeMessage.transformMessage(ObjectToMimeMessage.java:54)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
<小时/>

我的 XML 流程是:

<smtp:gmail-connector name="Gmail" validateConnections="true" doc:name="Gmail" contentType="text/html" bccAddresses="#[payload.email]" ccAddresses="#[payload.email]" fromAddress="#[payload.email]"/>
<flow name="Email" doc:name="Email">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8088" doc:name="HTTP" path="Email"/>
<http:static-resource-handler resourceBase="docroot" defaultFile="index.html" doc:name="HTTP Static Resource Handler"/>
</flow>
<flow name="Correo" doc:name="Correo">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8088" path="Facturacion" doc:name="HTTP" transformer-refs="Java"/>
<component doc:name="Generar Pedido" class="org.mule.transformers.EmailTransformer"/>
<smtp:outbound-endpoint responseTimeout="10000" doc:name="SMTP" password="pass" port="587" user="email%40gmail.com" from="#[payload.email]" to="#[payload.email]" connector-ref="Gmail" address="#[payload.email]"/>
</flow>

类转换器是:

public class EmailTransformer extends AbstractMessageTransformer {


@Override
public Object transformMessage(MuleMessage message, String outputEncoding)
throws TransformerException {
// TODO Auto-generated method stub
final Pedido pedido = (Pedido) message.getPayload();
System.out.println("Enviando email a la direccion de correo: "+pedido.getEmail()+"\n\n");
try {
MailUtils.stringToInternetAddresses(pedido.getEmail());
} catch (AddressException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
final StringBuilder mailMessage = new StringBuilder("A continuación le enviamos los datos del pedido que nos ha solicitado:").append("\n");
mailMessage.append("Nombre: " + pedido.getNombre()).append("\n");
mailMessage.append("NIF: " + pedido.getNIF()).append("\n");
mailMessage.append("Listado de productos: " + pedido.getProductos()).append("\n");
mailMessage.append("Recibe un cordial saludo. ");

message.setOutboundProperty(MailProperties.SUBJECT_PROPERTY, "Información del pedido que nos ha solicitado");
message.setOutboundProperty(MailProperties.TO_ADDRESSES_PROPERTY, pedido.getEmail());

return mailMessage.toString();
}
}

有人可以帮助我吗?谢谢!!

最佳答案

我在 EmailTransformer 中看到两个问题:

  • 假设消息有效负载可以转换为 Pedido ,虽然http:inbound-endpoint将生成一条有效负载为 InputStream 的消息类型。此转换无法正常工作。

  • 它没有定义它接受的类型的构造函数,例如:

    public EmailTransformer()
    {
    this.registerSourceType(DataTypeFactory.create(Pedido.class));
    this.setReturnDataType(DataTypeFactory.STRING);
    }

然后您需要将流添加到 Pedido变压器前面EmailTransformer .

或者,您可以重构 EmailTransformer直接使用InputStream .

关于java - 如何在 Mule ESB 上发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28785104/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com