SmtpMail.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /*
  37. try {
  38. // TODO: possibly cache ctor info object..
  39. Type stype = Type.GetType ("Mono.Mail.Smtp.SmtpSender");
  40. if (stype == null) {
  41. throw new Exception ("You must have Mono.Mail installed to send mail.");
  42. }
  43. Type[] types = new Type[2];
  44. types[0] = typeof (string);
  45. types[1] = message.GetType ();
  46. ConstructorInfo cinfo =
  47. stype.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null,
  48. CallingConventions.HasThis, types, null);
  49. cinfo.Invoke (new object[] {smtpServer, message});
  50. } catch (Exception) {
  51. throw new Exception ("Unable to call Mono.Mail.Smtp.SmtpSender");
  52. }
  53. */
  54. }
  55. public static void Send (string from, string to, string subject, string messageText)
  56. {
  57. MailMessage message = new MailMessage ();
  58. message.From = from;
  59. message.To = to;
  60. message.Subject = subject;
  61. message.Body = messageText;
  62. Send (message);
  63. }
  64. }
  65. } //namespace System.Web.Mail