Normally you would create a send pipeline with a MIME encoder and set the "send body part as attachment" to True. This however, will cause your email bodytext to state "This message has attachments.", no matter what you've set to be the SMTP.EmailBodyText-value.
To work arround this issue, you have to take the following steps:
- Create a custom send pipeline and add a MIME encoder, leave this as is.
- In your orchestration view, create a new MultiPartMessageType with 2 Message Parts, a BodyPart and an AttachmentPart. Set the "Message Body Part" property to respectively True and False. Also, set the "Type" property of the BodyPart to the schema of the message you want to add as an attachment.
The "Type" property of the AttachmentPart should be a .NET Class called "RawString".
This is a custom class that contains the following code:
using System;
using System.IO;
using System.Text;
using System.Xml.Serialization;
using System.Runtime.Serialization;
using Microsoft.XLANGs.BaseTypes;
namespace Microsoft.Samples.BizTalk.XlangCustomFormatters
{
public abstract class BaseFormatter : IFormatter
{
public virtual SerializationBinder Binder
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public virtual StreamingContext Context
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public virtual ISurrogateSelector SurrogateSelector
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public abstract void Serialize(Stream stm, object obj);
public abstract object Deserialize(Stream stm);
}
public class RawStringFormatter : BaseFormatter
{
public override void Serialize(Stream s, object o)
{
RawString rs = (RawString)o;
byte[] ba = rs.ToByteArray();
s.Write(ba, 0, ba.Length);
}
public override object Deserialize(Stream stm)
{
StreamReader sr = new StreamReader(stm, true);
string s = sr.ReadToEnd();
return new RawString(s);
}
}
[CustomFormatter(typeof(RawStringFormatter))]
[Serializable]
public class RawString
{
[XmlIgnore]
string _val;
public RawString(string s)
{
if (null == s)
throw new ArgumentNullException();
_val = s;
}
public RawString()
{
}
public byte[] ToByteArray()
{
return Encoding.UTF8.GetBytes(_val);
}
public override string ToString()
{
return _val;
}
}
}
- Then in a message assignement shape, type the following expression:
(POMessageOut is the outgoing message, POMessageIn is the message you want to attach).
POMessageOut.BodyPart = new Microsoft.Samples.BizTalk.XlangCustomFormatters.RawString("This is the body of the email.");
POMessageOut.AttPart = POMessageIn;
- That's pretty much it!
0 comments:
Post a Comment