Home Page › Forums › BizTalk 2004 – BizTalk 2010 › Sending Html mail with embedded image via the smtp adapter › Re: Sending Html mail with embedded image via the smtp adapter
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