Attachment is not showing in email

Hi,

Currently I’m testing an evaluation version of Aspose.Email. Currently I can only see encoded characters instead of the actual image I put in as an attachment. Also, when I set the message body to be html…it shows the html tags…not the actual data as it is rendered in a browser. (basically we have a form where the user can select the rows that they want to email from a gridview. We then use the string writer to grab the html of the rows they selected and coalesce this into an html string to put into the email body) Can give me some feedback? ( i have attached the email contents that i get from Aspose.Email, as well as the picture I put in as an attachment)
Here’s the code I used:

protected void mailSendButton_Click(object sender, EventArgs e)

{

StringBuilder sb = new StringBuilder();

StringWriter sw = new StringWriter(sb);

HtmlTextWriter writer = new HtmlTextWriter(sw);

reportGrid.RenderBeginTag(writer);

foreach (GridViewRow row in reportGrid.Rows)

{

TableCell cellCheck = null;

for (int i = 0; i < row.Cells.Count; i++)

{

TableCell cell = row.CellsIdea;

if (cell.Controls.Count > 0 && cell.Controls[0] is HtmlInputCheckBox)

{

cellCheck = cell;

}

}

if (cellCheck == null) continue;

HtmlInputCheckBox check = cellCheck.Controls[0] as HtmlInputCheckBox;

if (check.Checked)

{

row.RenderControl(writer);

}

}

reportGrid.RenderEndTag(writer);

Aspose.Email.Message msg = new Aspose.Email.Message();

msg.From = new Aspose.Email.Address("kshen@watchfire.com");

msg.ReplyTo = new Aspose.Email.Address("kshen@watchfire.com");

msg.AddAddress(new Aspose.Email.Address("kshen@watchfire.com"), Aspose.Email.Address.Type.To);

msg.Subject = “Broken Links Report”;

msg.Date = DateTime.Now;

msg.Confirmation = true;

msg.AllowRefusedAddresses = true;

Aspose.Email.TextHtmlBody htmlBody = new Aspose.Email.TextHtmlBody();

htmlBody.Content = Server.HtmlEncode(sb.ToString());

htmlBody.Charset = “UTF-8”;

Aspose.Email.AlternativeBody altBody = new Aspose.Email.AlternativeBody();

altBody.AddPart(htmlBody);

msg.Body = altBody;

Aspose.Email.Attachment embeddedImage = new Aspose.Email.Attachment(“c:\watchfirelogo.gif”);

msg.AddEmbeddedObject(embeddedImage);

msg.Send(new SmtpAccount(“1WFEMAIL”, 25, “kshen”, “hacknslash”), new ProgressMonitor());

Oh, I see why I’m not getting the HMTL to render correctly in the email body now. I forgot a line: htmlBody.Content = sb.ToString()…the data I put in my last example is encoded html. So forget I asked that question Smile.
But I’m still wondering why attachment is not showing up…and also, how do you get pictures to show up in the email body?

Dear Kristy,

Sorry for any delay. Please download the lastest hotfix 1.1.5 : http://www.aspose.com/Products/Aspose.Email/Releases/current/Aspose.Email.zip

To use embeded image, you have to add an embeded image, and set a content id for it. And then use content id to refer the image.

Here is some sample for how to use embeded image in email:

Aspose.Email.TextHtmlBody htmlBody = new Aspose.Email.TextHtmlBody();

htmlBody.Content = "This is alternative message content. " +
“”; //use contentid to refer the embeded image in the mail

htmlBody.Charset = “UTF-8”;
Aspose.Email.Attachment embeddedImage = new Aspose.Email.Attachment(“c:\watchfirelogo.gif”);

//set the contentid for embeded image
embeddedImage.ContentId = “image1”;
msg.AddEmbeddedObject(embeddedImage);

Aspose.Email.AlternativeBody altBody = new Aspose.Email.AlternativeBody();
altBody.AddPart(htmlBody);

msg.body = altBody;