15 de setembro de 2011

Obter uma mensagem renderizada com imagens do Exchange On-Line

Para utilizar este método necessita saber como fazer o BINDING e terá de ter disponível o ID da sua mensagem

 

using Microsoft.Exchange.WebServices.Autodiscover;
using Microsoft.Exchange.WebServices.Data;
using BodyType = Microsoft.Exchange.WebServices.Data.BodyType;
/// <summary>
/// Les the menssagem por id.
/// </summary>
/// <param name="messId">The mess id.</param>
/// <returns></returns>
public static string LeMenssagemPorId(string messId)
{
PropertySet psPropSet = new PropertySet(BasePropertySet.FirstClassProperties)
{
RequestedBodyType = BodyType.HTML
};
Item mess = Item.Bind(GetBinding(), messId, psPropSet);
mess.Body.BodyType = BodyType.HTML;

string sHTMLCOntent = mess.Body.Text;

FileAttachment[] attachments = null;

if (mess.Attachments.Count != 0)
{
attachments = new FileAttachment[mess.Attachments.Count];
for (int i = 0; i < mess.Attachments.Count; i++)
{
try
{
if (mess.Attachments[i].IsInline)
{
string sType = mess.Attachments[i].ContentType.ToLower();
if (sType.Contains("image"))
{
attachments[i] = (FileAttachment)mess.Attachments[i];
attachments[i].Load();
string sId = attachments[i].ContentId;
sType = sType.Replace("image/", "");
string oldString = "cid:" + sId;
string imagem =
Convert.ToBase64String(attachments[i].Content);
sHTMLCOntent = sHTMLCOntent.Replace(oldString,
"data:image/" + sType + ";base64," + imagem);
}
}
}
catch (Exception ex)
{
HttpContext.Current.Response.Write("Erro: " + ex.Message);
}
}
}



Sem comentários:

Enviar um comentário

Like