2

The following code is to send a mail by C# code.

 Assembly assembly = typeof(System.Net.Mail.SmtpClient).Assembly;
 Type tMailWriter = assembly.GetType("System.Net.Mail.MailWriter");
 object mailWriter = Activator.CreateInstance(tMailWriter, flags, null, new object[] { ms }, CultureInfo.InvariantCulture);
 msg.GetType().GetMethod("Send", flags).Invoke(msg, new object[] { mailWriter, true });

Regarding the System.Net.Mail.MailWriter, I cannot find this class by browsing the dll. Please see the screen shot. What is the problem? Where can I find it? Thank you.

Update:

In this question, I mainly focus on why we cannot browse some class in dll throw VS. Now I find the answer. It is not a public class.

enter image description here

Sun Robin
  • 583
  • 4
  • 13
  • are you looking for this one http://www.dotnetframework.org/default.aspx/4@0/4@0/untmp/DEVDIV_TFS/Dev10/Releases/RTMRel/ndp/fx/src/Net/System/Net/Mail/MailWriter@cs/1305376/MailWriter@cs – pushpraj Aug 19 '14 at 05:18
  • 1
    It is not public class, that's why this code sample gets it using reflection by name – Lanorkin Aug 19 '14 at 05:20
  • Dealing with non-public classes/methods is pain in general... Check out http://stackoverflow.com/questions/9595440/getting-system-net-mail-mailmessage-as-a-memorystream-in-net-4-5-beta for some hacks to deal with this class. – Alexei Levenkov Aug 19 '14 at 05:20
  • @Lanorkin Thank you. I forget this point. And I am just wondering why Microsoft doesn't mark this class as public for us developers to use easily. Otherwise, we have to use it by reflection. – Sun Robin Aug 19 '14 at 06:19

0 Answers0