Free Support Forum - aspose.com

MailMessage.IsBody is not working

I have downloaded the file Aspose.Email_5.5.0.msi file. and installed it. I have added the references for the namespaces Aspose.Email.Mail and Aspose.Email.Outlook.


Requirement:
Need one button on web page, if we click on it .msg file has to be saved at particular location along with attachment.

Code:
using (var mailMsg = new MailMessage())
{
mailMsg.To = new MailAddress("abc@xyz.com");
mailMsg.Subject = “Hellow”;
mailMsg.IsBodyHtml = true;
mailMsg.Body = "body{font-size: 13px;font-family: Segoe
UI,Tahoma,Arial,Verdana,sans-serif;line-height:18px;color:
#1F497D;}b{font-size: 12px;}

Hi,Please find the attached file (Format: .msg).

This request was generated via Oak Avenue Sample Application.

"
mailMsg.Attachments.Add(new Attachment(Server.MapPath("~/TDDPartIII.pdf") ));
var outlookMsg = MapiMessage.FromMailMessage(mailMsg);
const string strMsgFile = @"E:\sample.msg";
outlookMsg.Save(strMsgFile);
}
I am getting the .msg file with the same body.

Please help me to resolve this issue.

Thanks in Advance.

(Attached is the result image)


Hi Maruthi,


The problem is with your code segment where you are setting the message body. When you want to set Html inside email body, you need to use the HtmlBody property instead of Body. The following code sample, with correction highlighted, produces correct result in this case.

Code:

using (var mailMsg = new MailMessage())<o:p></o:p>

{

mailMsg.To = new MailAddress("abc@xyz.com");

mailMsg.Subject = "Hellow";

mailMsg.IsBodyHtml = true;

mailMsg.HtmlBody = "body{font-size: 13px;font-family: Segoe UI,Tahoma,Arial,Verdana,sans-serif;line-height:18px;color: #1F497D;}b{font-size: 12px;}

Hi,Please find the attached file (Format: .msg).

This request was generated via Oak Avenue Sample Application.

";

mailMsg.Attachments.Add(new Attachment(("a.pdf") ));

var outlookMsg = MapiMessage.FromMailMessage(mailMsg);

const string strMsgFile = @"sample.msg";

outlookMsg.Save(strMsgFile);

}