Adding multiple images


If i have more inline images say 30 so for adding those images in msg what should i do…
please reply soon

Hi Pooja,

You can have a look at the following code sample for your reference. It reads 10 images of JPG type from the folder EMAIL_11111 and adds it to the MailMessage. Please let us know if you have any difficulty in understanding the example. We’ll be glad to assist you further.

Sample Code:

MailMessage mail = new MailMessage();
mail.From = new MailAddress("");
mail.Subject = "This is an email";

string strDir = "EMAIL_11111\\";
DirectoryInfo d = new DirectoryInfo(strDir);
String strAllCidString = "";

foreach(var file in d.GetFiles("*.jpg"))
    strAllCidString = strAllCidString + "<img src=cid:" + file.Name.ToString() + ">\n";
    LinkedResource InlineImage = new LinkedResource(strDir + file.Name);
    InlineImage.ContentId = file.Name.ToString();

AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content", null, "text/plain");
AlternateView htmlView1 = AlternateView.CreateAlternateViewFromString("Here is an embedded image.\n" + strAllCidString, null, "text/html");

mail.Save(strDir + "Test.msg", MailMessageSaveType.OutlookMessageFormat);

// You can further add this message to a PST as follow:
MapiMessage mapi = MapiMessage.FromMailMessage(mail);
PersonalStorage pst = PersonalStorage.Create(strDir + "InlineImage.pst", FileFormatVersion.Unicode);
FolderInfo folderInfo = pst.RootFolder.AddSubFolder("Test Folder");


I used Aspose.Email 3.2.0 and .net 2.0 but it doesn’t work.Please check it. I also add ur code same as it is in my code…still not working…please reply soon.

Hi Pooja,

Please have a look at the atached complete .NET project and let us know if you still face problem.


Thank you so much…It works fine now…problem is that i am not adding license file in the project.

1.If i have rtf body or plain or html body how can add to mailmessage body.
please reply soon.

Hi Pooja,

Could you please elaborate your requirements so that we can assist you further in this regard? It’ll be better if you could create a new thread and mention your requirements in that.