Please send me Sample code for add inline images in pst file

Hi

Nice product. we are planing to purchase it.

we have only two issue.

can you solve it? also send me sample code for it.

1) How to add inline images to email in pst file.( I am creating new pst file and adding new emails in it. but i am not able to add inline images. if i added inline image then that is not visible in pst file. )

2) How to set Read and unread flags for emails in pst file.


Thanks in advance.



please reply me on following mail

Email :- maruti@cloudcodes.com , contact :- +918805544789

Hi Maruti,

Thank you for the feedback.

Please have a look at the following code sample that:

  1. Adds an inline image to the message using the LinkedResource collection
  2. Marks the message as Unread by setting the flag MapiMessageFlags.MSGFLAG_READ

Please feel free to write to us if you have any additional query/inquiry related to Aspose.Email. We’ll be glad to assist you further.

Sample Code:

//Create an instance of the MailMessage
MailMessage mail = new MailMessage();

//Set the addresses
mail.From = new MailAddress("test001@kerio.com");
mail.To.Add("test001@kerio.com");

//Set the content
mail.Subject = "This is an email";

//Create the plain text part
//It is viewable by those clients that don't support HTML
AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my plain text content", null, "text/plain");

//Create the HTML part.
//To embed images, we need to use the prefix 'cid' in the img src value.
//The cid value will map to the Content-Id of a Linked resource.
//Thus will map to a LinkedResource with a ContentId of 'companylogo'.
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image.", null, "text/html");

//create the LinkedResource (embedded image)
LinkedResource logo = new LinkedResource(@"Personalization.png", MediaTypeNames.Image.Png);
logo.ContentId = "companylogo";

//Add the LinkedResource to the appropriate view
mail.LinkedResources.Add(logo);

mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);

MapiMessage mapi = MapiMessage.FromMailMessage(mail);

//Mark the message unread
mapi.SetMessageFlags((mapi.Flags & ~MapiMessageFlags.MSGFLAG_READ));

File.Delete("InlineImagePst.pst");
PersonalStorage pst = PersonalStorage.Create("InlineImagePst.pst", FileFormatVersion.Unicode);

FolderInfo folderInfo = pst.RootFolder.AddSubFolder("TestFolder");
folderInfo.AddMessage(mapi);

Hi


Thank you for quick reply.

Please can you send me sample code to set mail as important. (Important flag).

Hi,


Please use the following code sample to achieve this and let us know if you need further assistance in this regard.


MailMessage msg = new MailMessage();


msg.Priority = MailPriority.High;


HI

Above code adding inline images working fine. But please can you guide me for adding two or more inline images in one mail.
Thank you.
Maruti Nedre

Hi

How to set Followup Flag in email?


Hi Maruti,

In order to add multiple inline images, you need to:

  1. Modify the AlternateView.CreateAlternateViewFromString statement so that it now includes the reference to the additional images as well
  2. Add additional LinkedResources to your message so as to be referred by the above statement
    For example, if you want to add 2 inline images, you can modify your code as follow:

Sample Code:

AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image. and another image.", null, "text/html");

//create the LinkedResource (embedded image)
LinkedResource logo1 = new LinkedResource(@"Chrysanthemum.jpg", MediaTypeNames.Image.Jpeg);
logo1.ContentId = "companylogo1";

LinkedResource logo = new LinkedResource(@"Desert.jpg", MediaTypeNames.Image.Jpeg);
logo.ContentId = "companylogo";

//Add the LinkedResource to the appropriate view
mail.LinkedResources.Add(logo);
mail.LinkedResources.Add(logo1);

Hi
Now i can add 2 inline images. But that are not visible in email body. I i added single image then it will visible in attachment and in email body also. but in case of two or more images , images are not visible in email body.

Hi Maruti,


Could you please give a try to the following code which adds two inline images in a mail which is added to PST? Both the the inline images are visible in mail body when opened in Outlook 2010.

//Create an instance of the MailMessage class
MailMessage mail = new MailMessage();

//Set the addresses
mail.From = new MailAddress("test001@kerio.com");
mail.To.Add("test001@kerio.com");

//Set the content
mail.Subject = “This is an email”;

//Create the plain text part
//It is viewable by those clients that don’t support HTML
AlternateView plainView = AlternateView.CreateAlternateViewFromString(“This is my plain text content”, null, “text/plain”);
AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image. and another image. ", null, “text/html”);

//create the LinkedResource (embedded image)
LinkedResource logo = new LinkedResource(@“Personalization.png”, MediaTypeNames.Image.Png);
logo.ContentId = “companylogo”;

LinkedResource logo1 = new LinkedResource(@“Keyboard.png”, MediaTypeNames.Image.Png);
logo1.ContentId = “companylogo1”;

mail.LinkedResources.Add(logo);
mail.LinkedResources.Add(logo1);

mail.AlternateViews.Add(plainView);
mail.AlternateViews.Add(htmlView);

MapiMessage mapi = MapiMessage.FromMailMessage(mail);

//Mark the message unread
mapi.SetMessageFlags((mapi.Flags & ~MapiMessageFlags.MSGFLAG_READ));

File.Delete(“InlineImagePst.pst”);
PersonalStorage pst = PersonalStorage.Create(“InlineImagePst.pst”, FileFormatVersion.Unicode);
FolderInfo folderInfo = pst.RootFolder.AddSubFolder(“TestFolder”);
folderInfo.AddMessage(mapi);

Please feel free to write us back if you have any other query in this regard.