Hi Maruti,
Thank you for the feedback.
Please have a look at the following code sample that:
- Adds an inline image to the message using the LinkedResource collection
- 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:
- Modify the AlternateView.CreateAlternateViewFromString statement so that it now includes the reference to the additional images as well
- 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 classMailMessage mail =
new MailMessage();
//Set the addressesmail.From =
new MailAddress(
"test001@kerio.com");
mail.To.Add(
"test001@kerio.com");
//Set the contentmail.Subject = “This
is an email”;
//Create the plain text part//It is viewable by those clients that don’t support HTMLAlternateView 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 unreadmapi.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.