ロゴとユーザーの署名の画像を埋め込んだhtml電子メールを送信しようとしています。私はApacheのコモンズメールを使用しています。私はApacheのサイトチュートリアルに従ってきましたが、ウェブ上でさまざまなアプローチを試みましたが、イメージを埋め込むことはできません。 これはイントラネットアプリケーションであり、とにかく外部からのアクセスをブロックするシングルサインオンの背後にあるため、埋め込みイメージを取得するためにURLを使用することはできません。 これは本当にhtmlではなく、アプリケーションがテンプレートとして使用するxmlです。 以下、xml-html(注記テキストが正しく表示され、埋め込まれた画像に問題があります)と画像を埋め込むためのコードを追加しました。誰かが間違いを指摘したり、解決策を提案したりできます。問題ありませんか?画像が埋め込まれたメールを送信する
結果のHTML/XML:
<?xml version="1.0" encoding="UTF-8"?><div style="margin-top: 20px; font-size: small;">
<br/>
<div class="auto-style1">
<div style="text-align: left;">
...
<div class="MsoNormal" style="text-align: right; padding-right: 100px; font-family: arial black,sans-serif;">
<img id="signature" src="cid:jrvoirylpp"/>
</div>
...
メール送信するために私のコード:
HtmlEmail htmlMail = new HtmlEmail();
initMail(htmlMail);//set commons parameters (host,port,...
htmlMail.setContent(htmlCorpoMessaggio, "text/html");
//i'm trying to retrieve the raw byte array from my app resources
InputStream is = this.getClass().getResourceAsStream(
String.format("%s%s",
Configurator.getString("Template.resources"),
Configurator.getString("Template.firma")));
byte[] image = IOUtils.toByteArray(is);
//can't send an url i'm trying to truly embed the image inside the mail message
DataSource ds = new ByteArrayDataSource(image, "image/png");
String cid = htmlMail.embed(ds, "signature");
//i need to replace the src="an app path" to cid
Document doc = XmlHelper.loadXMLFromString(htmlCorpoMessaggio);
NodeList nodeList = doc.getElementsByTagName("img");
Node currentNode = null;
for(int i = 0; i < nodeList.getLength(); i++)
{
currentNode = nodeList.item(i);
}
NamedNodeMap nodiAttributo = currentNode.getAttributes();
for(int i= 0 ; i < nodiAttributo.getLength() ; i++)
{
Node n = nodiAttributo.item(i);
if(n.getNodeName().equals("src"))
n.setNodeValue("cid:" + cid);
}
htmlCorpoMessaggio = XmlHelper.getStringFromDocument(doc);
for(MailAttachment allegato : allegati)
{
//la stringa vuota rappresenta la descrizione dell'allegato
htmlMail.attach(allegato.getDataSource(),
allegato.getFilename(),"",EmailAttachment.ATTACHMENT);
}
htmlMail.send();
@サムウォーレンも、とにかく、ありがとう、少なくとも誰かが答えている:)と私は何か新しいことを学んだ。 Unlickly Webアプリケーションはイントラネット内からWebからアクセスできず、とにかくすべてのリソースが認証されていない要求をブロックするssoシステムの背後にある –