SmtpMail.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // System.Web.Mail.SmtpMail.cs
  3. //
  4. // Author:
  5. // Lawrence Pit ([email protected])
  6. //
  7. //
  8. using System;
  9. using System.Net;
  10. using System.Reflection;
  11. namespace System.Web.Mail
  12. {
  13. /// <remarks>
  14. /// </remarks>
  15. public class SmtpMail
  16. {
  17. private static string smtpServer;
  18. // Constructor
  19. private SmtpMail ()
  20. {
  21. /* empty */
  22. }
  23. // Properties
  24. public static string SmtpServer {
  25. get { return smtpServer; }
  26. set { smtpServer = value; }
  27. }
  28. [MonoTODO]
  29. public static void Send (MailMessage message)
  30. {
  31. // delegate work to loosly coupled component Mono.Mail
  32. // Mono.Mail.Smtp.SmtpSender.Send (smtpServer, message);
  33. // NOTE: Mono.Mail is work in progress, and could be replaced by
  34. // another component. For now:
  35. throw new NotImplementedException("Mono.Mail component is work in progress");
  36. try {
  37. // TODO: possibly cache ctor info object..
  38. Type stype = Type.GetType ("Mono.Mail.Smtp.SmtpSender");
  39. if (stype == null) {
  40. throw new Exception ("You must have Mono.Mail installed to send mail.");
  41. }
  42. Type[] types = new Type[2];
  43. types[0] = typeof (string);
  44. types[1] = message.GetType ();
  45. ConstructorInfo cinfo =
  46. stype.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null,
  47. CallingConventions.HasThis, types, null);
  48. cinfo.Invoke (new object[] {smtpServer, message});
  49. } catch (Exception) {
  50. throw new Exception ("Unable to call Mono.Mail.Smtp.SmtpSender");
  51. }
  52. }
  53. public static void Send (string from, string to, string subject, string messageText)
  54. {
  55. MailMessage message = new MailMessage ();
  56. message.From = from;
  57. message.To = to;
  58. message.Subject = subject;
  59. message.Body = messageText;
  60. Send (message);
  61. }
  62. }
  63. } //namespace System.Web.Mail