我正在尝试发送带有示例项目的电子邮件。我尝试做的是一个样本书店,用户收到一个表格,用订单填写(名称,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();
}
}
任何人都可以帮助我吗? 谢谢!
答案 0 :(得分:2)
我在EmailTransformer
中看到了两个问题:
它假定消息有效负载可以强制转换为Pedido
,尽管http:inbound-endpoint
将生成有效负载为InputStream
类型的消息。此演员阵容无效。
它没有定义它接受的类型的构造函数,如:
public EmailTransformer()
{
this.registerSourceType(DataTypeFactory.create(Pedido.class));
this.setReturnDataType(DataTypeFactory.STRING);
}
然后,您需要在Pedido
前面的EmailTransformer
转换器添加一个流。
或者,您可以重构EmailTransformer
以直接使用InputStream
。