943,607 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 4223
  • C# RSS
Jul 28th, 2009
0

Embedded images on email

Expand Post »
Hi.

I have a problem when trying to embed pictures to an email. It works fine on windows server and the email is shown correct but when I try to put it in production which runs on Linux (mono 2.4) it sends the pictures as attachments (and deletes the first one of them.). I have tried alot and have searched everywhere but with no luck.

The code below works fine in windows but attach the embedded pictures in mono. Any surgestions what I can try, I'm running out of idears.

C# Syntax (Toggle Plain Text)
  1.  
  2. mail.BodyEncoding = System.Text.Encoding.UTF8;
  3. //AddSignature(ref pBodyPlain);
  4. string mBodyHtmlBn = "";
  5. mBodyHtmlBn += "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
  6. mBodyHtmlBn += "<HTML><HEAD><META http-equiv=Content-Type content=\"text/html; \"> </HEAD> ";
  7. mBodyHtmlBn += "<body bgcolor=\"#EEEEEE\">";
  8. mBodyHtmlBn += "<table bgcolor=\"#FFFFFF\" border=\"1\" cellpadding=\"8\" bordercolor=\"#CCCCCC\" width=\"500\">";
  9. mBodyHtmlBn += "<tr><td bgcolor=\"B2C6D9\"><img src='cid:header_left' align=\"left\"> <img src='cid:header_right' align=\"right\"></td></tr>";
  10. mBodyHtmlBn += "<tr><td>";
  11. mBodyHtmlBn += "<font face=\"verdana, arial\" size=\"2\">";
  12. mBodyHtmlBn += pBodyHtml;
  13. mBodyHtmlBn += "</font>";
  14. mBodyHtmlBn += "<img src='cid:logo_bottom' align=\"right\">";
  15. mBodyHtmlBn += "<br><br>";
  16. mBodyHtmlBn += "</td></tr></table>";
  17. mBodyHtmlBn += "</body></HTML>";
  18.  
  19. // PLAIN / HTML
  20. //System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(pBodyPlain, null, "text/plain");
  21. System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(mBodyHtmlBn, new System.Net.Mime.ContentType("text/html")); //multipart/mixed")); //, null, "text/html");
  22.  
  23. System.Net.Mail.LinkedResource logo = new System.Net.Mail.LinkedResource(System.AppDomain.CurrentDomain.BaseDirectory + "/images/mailheader_newsletter.gif"); // + sHeaderImg);
  24. logo.ContentId = "header_left";
  25. //add the LinkedResource to the appropriate view
  26. htmlView.LinkedResources.Add(logo);
  27.  
  28. System.Net.Mail.LinkedResource logo2 = new System.Net.Mail.LinkedResource(System.AppDomain.CurrentDomain.BaseDirectory + "/images/mail_logo.gif", "image/gif");
  29. logo2.ContentId = "header_right";
  30. //add the LinkedResource to the appropriate view
  31. htmlView.LinkedResources.Add(logo2);
  32.  
  33. System.Net.Mail.LinkedResource logo3 = new System.Net.Mail.LinkedResource(System.AppDomain.CurrentDomain.BaseDirectory + "/images/mail_logo_bottom.gif", "image/gif");
  34. logo3.ContentId = "logo_bottom";
  35. //add the LinkedResource to the appropriate view
  36. htmlView.LinkedResources.Add(logo3);
  37.  
  38. mail.AlternateViews.Add(htmlView);
  39.  
  40. mail.Body = mBodyHtmlBn;
  41. System.Net.Mail.SmtpClient mSmtpClient = new System.Net.Mail.SmtpClient(Config.GetString("SMTP"));
  42.  
  43. //mail.IsBodyHtml = true;
  44. mSmtpClient.Send(mail);
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
sniper1983 is offline Offline
30 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Is it possible create pivot table and copy to data table using c#.net?
Next Thread in C# Forum Timeline: login window in main window





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC