Scenario
File-to-Mail
Requisito
Allegare file di testo a una mail.
Enterprise Service Builder
![](https://www.nick4name.eu/wp-content/uploads/2018/02/125.png)
![](https://www.nick4name.eu/wp-content/uploads/2018/02/126.png)
![](https://www.nick4name.eu/wp-content/uploads/2018/02/127.png)
![](https://www.nick4name.eu/wp-content/uploads/2018/02/128.png)
Il seguente mapping converte il contesto in un’unica stringa in cui ogni elemento di context diventa una riga.
La stringa viene mossa in Content.
![](https://www.nick4name.eu/wp-content/uploads/2018/02/129.png)
![](https://www.nick4name.eu/wp-content/uploads/2018/02/130.png)
L’UDF concatRows converte l’array in una stringa in cui gli elementi dell’array sono separati tramite new line.
public void concatRows(String[] rows, ResultList result, Container container) throws StreamTransformationException{
String t = "";
for (int i = 0; i < rows.length; i++) {
if (i > 0) {
t += System.getProperty("line.separator") + rows[i];
} else {
t += rows[i];
}
}
result.addValue(t);
}
![](https://www.nick4name.eu/wp-content/uploads/2018/02/131.png)
Integration Builder
Il canale sender file
Nel caso in cui l’Adapter sender non preveda il tab Content Convertion (per esempio l’SFTP) si può adottare il modulo AF_Modules/MessageTransformBean
![](https://www.nick4name.eu/wp-content/uploads/2018/02/132.png)
In questo caso, il file letto
Num. Mensaje;Fecha;Error
W0051326G J20150721;20150721;Muy Sres. nuestros:
W0051326G J20150721;20150721;Nos referimos a su/s factura/s abajo relacionada/s.
W0051326G J20150721;20150721;Al objeto de verificar su conformidad, y como quiera que no
assume il seguente payload
![](https://www.nick4name.eu/wp-content/uploads/2018/02/133.png)
Il canale receiver mail
I parametri della mail devono essere assunti dal mapping e quini impostare Using Mail Package.
![](https://www.nick4name.eu/wp-content/uploads/2018/02/134.png)
Prerequisito perché il file in attach abbia il nome del file di turno
![](https://www.nick4name.eu/wp-content/uploads/2018/02/135-300x137.png)
La Receiver Interface
![](https://www.nick4name.eu/wp-content/uploads/2018/02/136.png)
Il test
![](https://www.nick4name.eu/wp-content/uploads/2018/02/137.png)
![](https://www.nick4name.eu/wp-content/uploads/2018/02/138.png)
Limitazioni
Se il canale sender è configurato per leggere più file, questi verranno inviati come attach in mail separate.
La presente soluzione gestisce solo file di testo e non anche file binary.