locked
Converting from CDO.Message to System.Net.Mail RRS feed

  • Question

  • Hello everyone....

    I would like to convert some code from CDO to System.net.mail.  In particular, I need to Embed an entire web page (included images) into the email.  In CDO, it was done like this:

    objSMTP = CreateObject("CDO.Message")
    objSMTP.CreateMHTMLBody("http://www.microsoft.com", 0)

    Is there a way to do this with System.Net.Mail.Message?

    Thanks!

    Forch

    Friday, November 18, 2005 2:45 PM

Answers

  • We do not have MHTML support in System.Net.Mail yet.  You can create HTML content w\ images using "Linked Resources".  We would like to hear more about your scenario (ie. how you use MHTML support).  Please send mail to nclasks@microsoft.com.  This alias goes directly to the product team and is intended to allow customers to submit new feature asks.


    The followign assumes the images and html content are on the local harddrive.



    public class MailTest
    {
     public static void Main()
     {
      try
      {
       //CREATE A MAIL CLIENT
       SmtpClient MailClient = new SmtpClient("localhost");
       
       //SET FROM, TO
       MailMessage Message = new MailMessage("<FROM>", "<TO>");
       
       //SET SUBJECT
       Message.Subject = "System.Net.Mail is easy";

       //SET BODY
       StreamReader sr = File.OpenText("VS2005.htm");
       Message.Body = sr.ReadToEnd();
       sr.Close();

       //SET BODY TYPE TO HTML
       Message.IsBodyHtml = true;

       //ATTACHMENTS
       Message.Attachments.Add(new Attachment("TeamSystem.gif", "image/gif"));


       //SEND IT!!!
       MailClient.Send(Message);

       Console.WriteLine("Mail Successfully Sent");
      }
      catch(Exception e)
      {
       Console.WriteLine(e);
      }
      finally
      {
      
      }
     }
    }

     


     

    Wednesday, November 23, 2005 5:28 PM