Free Support Forum - aspose.com

How to Add an inline image as attachment in MailMessage/ MapiMessage

How to Add an inline image as an attachment in MailMessage/ MapiMessage.
Please Share Code for the same.

thanks

@ravikumarchopra,

Please use the code snippet given below to insert inline attachments.

MailMessage msg = new MailMessage("from@test.com", "to@test.com", "Subject", "test message");
string Html = "<img src=\"cid:image1\" />";
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Html, null, "text/html");

// Create the LinkedResource (embedded image) and Add the LinkedResource to the appropriate view
LinkedResource linkedImage = new LinkedResource("ImagePath", MediaTypeNames.Image.Jpeg)
{
    ContentId = "image1"
};

msg.LinkedResources.Add(linkedImage);
msg.AlternateViews.Add(htmlView);
msg.Save("MsgFilePath", MsgSaveOptions.DefaultMsg);

We hope that this answers your question. Please feel free to contact us if additional information is required.