Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Sending Html mail with embedded image via the smtp adapter
- This topic has 6 replies, 1 voice, and was last updated 9 years, 2 months ago by
community-content.
-
AuthorPosts
-
-
August 18, 2010 at 10:58 AM #25671
Hello,
First of all, sorry for my bad english, I’m a french biztalk developer!
Here is my problem:
I use a biztalk orchestration to :
– receive a xml file which represents the email to send : the recipients, the sender, … and especially the url of the html page to send. This page is on the intranet and contains text and images.
– construct the outgoing message (a multipart message) and to set the context properties : outmsg(SMTP.from), outmsg(SMTP.subject), …. I set the SMTP.EmailBodyFile property to my url.
– send the email via the smtp adapter
It works but the problem is that when the recipient receive the mail, he has to download the pictures.
I need to embed the pictures in the mail, but I don’t know how to do this.
In the past, I was sending emails with .NET (and not with Biztalk), so I used the AlternateViews of System.Net.Mail in order to embed the pictures,
With biztalk I am a little bit lost.
Any help appreciated,
Thank you very much!
-
August 18, 2010 at 12:16 PM #25672
Hi,
Have a look a the following blog and see if the steps taken to embed images in an email sent through SMTP adapter in BizTalk help you achieve what you need:
http://blogdoc.biztalk247.com/article.aspx?page=ca1cf68a-ab23-4a1d-ad4c-61011bba83cb
Daniel.
-
August 19, 2010 at 4:53 AM #25678
Hi, thank you for your reply,
I have already found this link, but unfortunately, it doesn’t help me because here the picture to embed is a second message part.
In my case, pictures are in the html body (referenced by url), so I think that “multipart/related” is not helpful for me.but I’m maybe mistaken
-
August 19, 2010 at 5:17 AM #25680
In the Html pictures are always <img> tags with a Url, you cannot put image data directly in the Html document.
This rule applies with Html mail.
The way images are embedded in Html email is to add the image as a MIME part to the email and then in the img tag set the src attribute to the Content-Id of the MIME part. There is a special Url syntax for this.e.g. if this is the MIME header for the image part:
—-=_NextPart_001_000D_01C79667.1A2EEFB0
Content-Type: image/gif
Content-Transfer-Encoding: base64
Content-Location: http://localhost/images/logo.gif
Content-ID: 1C7AE6B1-6728-4a5e-8D64-02F27B91B666Then in your Html mail your add an <img> node:
<img src=”cid:1C7AE6B1-6728-4a5e-8D64-02F27B91B666″ />-
August 19, 2010 at 8:13 AM #25684
Ok so if I have understood correctly,
in my orchestration:
1) for each picture in my HTTP content (ex: http://localhost/logo1.gif), I set a new part (example: partImage1 of type xmldocument) in my multi-part message :
outMsg.partImage1(MIME.ContentLocation) = http://localhost/logo.gif“
I set a CID programmatically : outMsg.partImage1(MIME.ContentID) = 12345;
2) programmatically, I replace in my HTML the node like this : src=”cid:12345″ ?
-
August 19, 2010 at 2:54 PM #25693
You don’t have to define specific message parts on your message. Each BizTalk message is inherently a multipart message.
You have to load the image file into the message part. You will need a C# library to do this:
public class StreamFactory : Microsoft.XLANGs.BaseTypes.IStreamFactory
{
Stream stream;public StreamFactory(Stream stream)
{
if (null == stream)
throw new ArgumentException();this.stream = stream;
}Stream IStreamFactory.CreateStream()
{
return stream;
}
}public class MessageHelper
{
public void AddImagePart(XLANGMessage message, string filepath, string contentId)
{
try
{
StreamFactory factory = new StreamFactory(new FileStream(filepath, Open, Read, Read));
int count = message.Count;
message.AddPart(factory, string.Format(“Attachment_{0}”, count));
message[count].SetPartProperty(typeof(MIME.FileName), Path.GetFileName(filepath));
message[count].SetPartProperty(typeof(MIME.ContentID), contentId);
}
finally
{ //important to decrement reference count and stop memory leaks
message.Dispose();
}
}
}Then in your html set the img src to the ContentID
-
August 23, 2010 at 4:56 AM #25709
thank you very much, my problem is solved !
-
-
-
-
-
-
-
AuthorPosts
- The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.