Sending different Email types with ASP.Net


/ Published in: C#
Save to your folder(s)

Como insertar imgenes en un envio via email en ASP.NET


Copy this code and paste it in your HTML
  1. try
  2.  
  3. {
  4.  
  5. MailMessage mail = new MailMessage();
  6.  
  7. mail.To.Add("[email protected]");
  8.  
  9. mail.From = new MailAddress("[email protected]");
  10.  
  11. mail.Subject = "Test with Image";
  12.  
  13. string Body = <b>Welcome to codedigest.com!!</b><br><BR>Online resource for .net articles.<BR><img alt=\"\" hspace=0 src=\"cid:imageId\" align=baseline border=0 >";
  14.  
  15.  
  16.  
  17. AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body, null, "text/html");
  18.  
  19. LinkedResource imagelink = new LinkedResource(Server.MapPath(".") + @"\codedigest.png", "image/png");
  20.  
  21. imagelink.ContentId = "imageId";
  22.  
  23. imagelink.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
  24.  
  25. htmlView.LinkedResources.Add(imagelink);
  26.  
  27. mail.AlternateViews.Add(htmlView);
  28.  
  29. SmtpClient smtp = new SmtpClient();
  30.  
  31. smtp.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
  32.  
  33. smtp.Send(mail);
  34.  
  35. }
  36.  
  37. catch (Exception ex)
  38.  
  39. {
  40.  
  41. Response.Write(ex.Message);
  42.  
  43. }

URL: http://www.codedigest.com/Articles/ASPNET/95_Sending_Email_using_C__and_ASPNet_20.aspx

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.