Prabu Spark

Prabu Spark

  • NA
  • 124
  • 204.4k

need help to send email with background images and text?

Mar 5 2014 3:24 AM
Hi sir,
Tell me the steps to send email with background images and text with top of background. I tried the below code the text and background will appear separately. Kindly give me the solution for this problem.

Code:
*************



string path = Server.MapPath(@"images/prof_bg.jpg"); // my logo is placed in images folder

LinkedResource logo = new LinkedResource(path);
logo.ContentId = "companylogo";
// done HTML formatting in the next line to display my logo
AlternateView av1 = AlternateView.CreateAlternateViewFromString("<html><body background=cid:companylogo><br><h1></h1></body></html>"+"Hi this is J.Prabu", null, MediaTypeNames.Text.Html);
av1.LinkedResources.Add(logo);

MailMessage MyMailMessage = new MailMessage("[email protected]", "[email protected]");


MyMailMessage.Subject = "Testing Mail";


string Body = "<b>Welcome to popfly!!</b><br><img alt=\"\" hspace=0 src=\"cid:imageId\" align=baseline border=0 >";



AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");

LinkedResource imagelink = new LinkedResource(Server.MapPath(@"images/prof_bg.jpg"), "image/jpeg");

imagelink.ContentId = "imageId";

imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;

htmlView.LinkedResources.Add(imagelink);

MyMailMessage.AlternateViews.Add(htmlView);



MyMailMessage.IsBodyHtml = true;
NetworkCredential mailAuthentication = new NetworkCredential("[email protected]", "123");
SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
mailClient.EnableSsl = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.EnableSsl = true;
mailClient.Send(MyMailMessage);



Answers (1)