The code sample sends HTML E-Mail messages that can include images from a C# program.
We can Use AlternateView and LinkedResource classes to create an html email and embed the image as a linked resource instead of attachment. we can also have to change the url / src of the image to the format "cid:ContentId". It will work for both img and background. Here is a code
//create the mail message MailMessage mail = new MailMessage();
//set the addresses mail.From = new MailAddress("user@gmail.com"); mail.To.Add("you@gmail.com");
//set the content mail.Subject = "Test mail";
//first we create the Plain Text part AlternateView plainView = AlternateView.CreateAlternateViewFromString("This is my text , viewable by those clients that don't support html", null, "text/plain");
//then we 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 'logo' AlternateView htmlView = AlternateView.CreateAlternateViewFromString("Here is an embedded image." ", null, "text/html");
//create the LinkedResource (embedded image) LinkedResource logo = new LinkedResource( "c:\\temp\\companylogo.gif" ); logo.ContentId = "logo"; //add the LinkedResource to the appropriate view htmlView.LinkedResources.Add(logo);
//add the views mail.AlternateViews.Add(plainView); mail.AlternateViews.Add(htmlView);
//send the message SmtpClient smtp = new SmtpClient("127.0.0.1"); //specify the mail server address smtp.Send(mail);
|
| Author: Nirupa Rani Acharya 27 Jul 2008 | Member Level: Bronze Points : 1 |
please send javascript code for submitting a page without using a submit button but using an image on the login window..
|