Mirth Connect:处理附件
Mirth Connect: Processing Attachment
Mirth Connect 服务器 3.5.1,Java 版本:1.8.0_171
我已经成功地将表单数据从 POSTMAN(参见 postman.xml)发送到 MIRTH(参见下文 JavaScript Writer)。我的 JavaScript Writer 可以抓取所有信息,除了我被困在如何处理 base64 文件内容上。
此代码 运行 没有错误,但我收到的电子邮件没有附件。其他都还好。
postman.xml:
<HttpRequest>
<Content boundary="--------------------------287734394493965736503744" multipart="yes">
<Part>
<Headers>
<Content-Disposition>form-data; name="channelFilter"</Content-Disposition>
</Headers>
<Content multipart="no">attachment</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="to"</Content-Disposition>
</Headers>
<Content multipart="no">coisox@gmail.com</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="cc"</Content-Disposition>
</Headers>
<Content multipart="no">coisox3@gmail.com</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="subject"</Content-Disposition>
</Headers>
<Content multipart="no">From Postman With Attachment</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="body"</Content-Disposition>
</Headers>
<Content multipart="no">Lalala</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="file"; filename="xls.png"</Content-Disposition>
<Content-Type>image/png</Content-Type>
</Headers>
<Content encoding="Base64" multipart="no">iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAA3NCSVQICAjb4U/gAAAACXBIWXMA AAG7AAABuwE67OPiAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAWJQTFRF ////4uLrhLtZ4uXmwcbLhL1a4ubn4uXnhL1ahL1bhb5bhr5dh79eh79fiL9fiL9gicBgi8FjjMFl jcJmjsJoj8Noj8NpkMNqkcRrksVtk8VvlMZvlcZxlsdyl8d0mMV4mch2msl4nMp6nst9oMyAoc2B o8iMo86Epc+Gps+Ip9CJqtGMq9KOr9SUsLe9sNWVsdWWs9aZtLvAtbzBtdebttidt9ifuNmfutqi u9qjvNumwN2qwN2rwcfMxuCyyOG1yeK3ytHYytTUzNzGzeS8zuW9zuW+z9Xb0ObA0ebB0ebC0+fD 1tvf1unH1unI2OrL2evN2+zP3ODj3eDj3u3S3u3T4O7V4uXn4u/Y5PDa5PHb5fHc5fHd5vLe5/Lf 6PPh6fPi7vbo7/bp7/bq8Pfq8ffs8vju8/nv9Pnw9Pnx9frx9fry9/v1+Pv1+fz3+vz5+/35/P36 /P37/f78///+////UwWFaAAAAAh0Uk5TABo8psDJ5upYXiAEAAAB00lEQVRYw93X90/CQBQHcLBa nrhn3RsHiooK7j1Q3LPiXrhBEd//b4GqRW3vtedPfJP2JZfcJ3m53F3OZtPGLoiyQbJtjNgdsmF6 WYIgMwCWIDIBhiCzAWOBAhgKJMBIoAEGAhHQF6iArkAG9AQ6oCOwgEGWwAImexkCC9gdYAgyU5g0 7kImZG32O5YArWAN0AgWgW/BKvAlWAY+BeuAKnAAKYEHSApcQELgAxSBE5DXeAH5/4CsHDCRxvlf gKn5ivALAJPJbKA4VfLUT41rdMxTQAL8cW+ieF580BAdVgcrQqjkwU0BPPjWBtDyil7owaA6OIMn QxMHsWlSC0G8qyq7wXXQAFGsU/6FThJQcIRH+3herAXCOJ5HXwXpFvGpBrSA7x2fVzvJy7iCuAlp ADRvvSNeuGlAH8ZiOJIOAFR6Q/haSwGaX9DvxXjHDwAg9wz7CUDpFW4ALOJjtQKsS5JU6QTnwlgT QHkEuwnAEl6WKEtxjNsKkMx1UXkcMbwXwXAJAZgKtyRK9eky1NwngdN86DpU6ttyHcdmqm91SZl+ Hpg8VNs5j/X2Od2LZZaWACcQ2Pn/qy2DANHcfNH00/dHBNOP7/Q47H883wVyF6KQmv8Bq6jVN1IO SxsAAAAASUVORK5CYII=</Content>
</Part>
</Content>
</HttpRequest>
Java编剧:
var email = new Packages.org.apache.commons.mail.SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new Packages.org.apache.commons.mail.DefaultAuthenticator("myusername", "mypassword"));
email.setSSLOnConnect(true);
var part = connectorMessage.getRawData().split('<Part>');
for(i=1; i<part.length; i++) {
var disposition = part[i].split('<Content-Disposition>')[1].split('</Content-Disposition>')[0];
var name = disposition.split('; name="')[1].split('"')[0];
var value = '';
if(disposition.indexOf('; filename="')>-1) {
var filename = disposition.split('; filename="')[1].split('"')[0];
var type = part[i].split('<Content-Type>')[1].split('</Content-Type>')[0];
value = part[i].split('<Content encoding="Base64" multipart="no">')[1].split('</Content>')[0];
//var file = addAttachment(value.encodedData, type);
var file = addAttachment(value, type);
}
else {
value = part[i].split('<Content multipart="no">')[1].split('</Content>')[0];
}
email.setFrom("test@gmail.com");
if(name=='to') email.addTo(value);
else if(name=='cc') email.addCc(value);
else if(name=='subject') email.setSubject(value);
else if(name=='body') email.setMsg(value);
}
email.send();
您的问题是,您正在使用 addAttachment
方法。如果您只是像您一样调用此方法,那么它与您放在一起的电子邮件对象无关,而是向 Mirth 邮件添加附件。您应该会在已处理消息的频道中看到一个附件选项卡,其中包含您的附件。
阅读有关如何在您使用的电子邮件库中添加附件的文档,并采取相应措施。也许它就像调用 email.addAttachment()
一样简单,但我不知道。
PS。为什么不使用 Mirth 的 XML 处理能力来访问 XML 的不同部分,而不是手动拆分 XML 字符串?
PPS。为什么不使用 Mirth 的 SMTP 发件人而不是全部手动完成?
Mirth Connect 服务器 3.5.1,Java 版本:1.8.0_171
我已经成功地将表单数据从 POSTMAN(参见 postman.xml)发送到 MIRTH(参见下文 JavaScript Writer)。我的 JavaScript Writer 可以抓取所有信息,除了我被困在如何处理 base64 文件内容上。
此代码 运行 没有错误,但我收到的电子邮件没有附件。其他都还好。
postman.xml:
<HttpRequest>
<Content boundary="--------------------------287734394493965736503744" multipart="yes">
<Part>
<Headers>
<Content-Disposition>form-data; name="channelFilter"</Content-Disposition>
</Headers>
<Content multipart="no">attachment</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="to"</Content-Disposition>
</Headers>
<Content multipart="no">coisox@gmail.com</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="cc"</Content-Disposition>
</Headers>
<Content multipart="no">coisox3@gmail.com</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="subject"</Content-Disposition>
</Headers>
<Content multipart="no">From Postman With Attachment</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="body"</Content-Disposition>
</Headers>
<Content multipart="no">Lalala</Content>
</Part>
<Part>
<Headers>
<Content-Disposition>form-data; name="file"; filename="xls.png"</Content-Disposition>
<Content-Type>image/png</Content-Type>
</Headers>
<Content encoding="Base64" multipart="no">iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAAA3NCSVQICAjb4U/gAAAACXBIWXMA AAG7AAABuwE67OPiAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAWJQTFRF ////4uLrhLtZ4uXmwcbLhL1a4ubn4uXnhL1ahL1bhb5bhr5dh79eh79fiL9fiL9gicBgi8FjjMFl jcJmjsJoj8Noj8NpkMNqkcRrksVtk8VvlMZvlcZxlsdyl8d0mMV4mch2msl4nMp6nst9oMyAoc2B o8iMo86Epc+Gps+Ip9CJqtGMq9KOr9SUsLe9sNWVsdWWs9aZtLvAtbzBtdebttidt9ifuNmfutqi u9qjvNumwN2qwN2rwcfMxuCyyOG1yeK3ytHYytTUzNzGzeS8zuW9zuW+z9Xb0ObA0ebB0ebC0+fD 1tvf1unH1unI2OrL2evN2+zP3ODj3eDj3u3S3u3T4O7V4uXn4u/Y5PDa5PHb5fHc5fHd5vLe5/Lf 6PPh6fPi7vbo7/bp7/bq8Pfq8ffs8vju8/nv9Pnw9Pnx9frx9fry9/v1+Pv1+fz3+vz5+/35/P36 /P37/f78///+////UwWFaAAAAAh0Uk5TABo8psDJ5upYXiAEAAAB00lEQVRYw93X90/CQBQHcLBa nrhn3RsHiooK7j1Q3LPiXrhBEd//b4GqRW3vtedPfJP2JZfcJ3m53F3OZtPGLoiyQbJtjNgdsmF6 WYIgMwCWIDIBhiCzAWOBAhgKJMBIoAEGAhHQF6iArkAG9AQ6oCOwgEGWwAImexkCC9gdYAgyU5g0 7kImZG32O5YArWAN0AgWgW/BKvAlWAY+BeuAKnAAKYEHSApcQELgAxSBE5DXeAH5/4CsHDCRxvlf gKn5ivALAJPJbKA4VfLUT41rdMxTQAL8cW+ieF580BAdVgcrQqjkwU0BPPjWBtDyil7owaA6OIMn QxMHsWlSC0G8qyq7wXXQAFGsU/6FThJQcIRH+3herAXCOJ5HXwXpFvGpBrSA7x2fVzvJy7iCuAlp ADRvvSNeuGlAH8ZiOJIOAFR6Q/haSwGaX9DvxXjHDwAg9wz7CUDpFW4ALOJjtQKsS5JU6QTnwlgT QHkEuwnAEl6WKEtxjNsKkMx1UXkcMbwXwXAJAZgKtyRK9eky1NwngdN86DpU6ttyHcdmqm91SZl+ Hpg8VNs5j/X2Od2LZZaWACcQ2Pn/qy2DANHcfNH00/dHBNOP7/Q47H883wVyF6KQmv8Bq6jVN1IO SxsAAAAASUVORK5CYII=</Content>
</Part>
</Content>
</HttpRequest>
Java编剧:
var email = new Packages.org.apache.commons.mail.SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new Packages.org.apache.commons.mail.DefaultAuthenticator("myusername", "mypassword"));
email.setSSLOnConnect(true);
var part = connectorMessage.getRawData().split('<Part>');
for(i=1; i<part.length; i++) {
var disposition = part[i].split('<Content-Disposition>')[1].split('</Content-Disposition>')[0];
var name = disposition.split('; name="')[1].split('"')[0];
var value = '';
if(disposition.indexOf('; filename="')>-1) {
var filename = disposition.split('; filename="')[1].split('"')[0];
var type = part[i].split('<Content-Type>')[1].split('</Content-Type>')[0];
value = part[i].split('<Content encoding="Base64" multipart="no">')[1].split('</Content>')[0];
//var file = addAttachment(value.encodedData, type);
var file = addAttachment(value, type);
}
else {
value = part[i].split('<Content multipart="no">')[1].split('</Content>')[0];
}
email.setFrom("test@gmail.com");
if(name=='to') email.addTo(value);
else if(name=='cc') email.addCc(value);
else if(name=='subject') email.setSubject(value);
else if(name=='body') email.setMsg(value);
}
email.send();
您的问题是,您正在使用 addAttachment
方法。如果您只是像您一样调用此方法,那么它与您放在一起的电子邮件对象无关,而是向 Mirth 邮件添加附件。您应该会在已处理消息的频道中看到一个附件选项卡,其中包含您的附件。
阅读有关如何在您使用的电子邮件库中添加附件的文档,并采取相应措施。也许它就像调用 email.addAttachment()
一样简单,但我不知道。
PS。为什么不使用 Mirth 的 XML 处理能力来访问 XML 的不同部分,而不是手动拆分 XML 字符串?
PPS。为什么不使用 Mirth 的 SMTP 发件人而不是全部手动完成?