How to insert backgroud image in mail bdy through c

To insert a background image in an email body using C#, you can use the System.Net.Mail namespace and create a AlternateView object to specify the HTML content of the email. Here's an example:

using System;
using System.Net.Mail;
using System.Net.Mime;

// Create a new MailMessage object
MailMessage mail = new MailMessage();

// Set the sender and recipient
mail.From = new MailAddress("[email protected]");
mail.To.Add("[email protected]");

// Set the subject
mail.Subject = "Test Email with Background Image";

// Create a new AlternateView object to specify the HTML content
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(
    "<html><body><img src='cid:background-image' style='width:100%; height:100%; position:fixed; top:0; left:0;'></body></html>",
    MediaTypeNames.Text.Html);

// Add the background image as an attachment
Attachment backgroundImage = new Attachment("background-image.jpg");
backgroundImage.ContentId = "background-image";
mail.Attachments.Add(backgroundImage);

// Add the HTML view to the email
mail.AlternateViews.Add(htmlView);

// Send the email
SmtpClient client = new SmtpClient();
client.Send(mail);

In this example, we create a new MailMessage object and set the sender, recipient, and subject. We then create a new AlternateView object to specify the HTML content of the email, which includes an <img> tag that references the background image using a content ID (cid:background-image).

We also add the background image as an attachment to the email using the Attachment class, and set its content ID to match the one used in the HTML content.

Finally, we add the HTML view to the email using the AlternateViews property, and send the email using an SmtpClient object.

Note that the background image should be a JPEG or PNG file, and its file name should match the one specified in the Attachment object. Also, make sure to adjust the style attribute of the <img> tag to position the background image correctly in the email body.