SmtpMail.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // System.Web.Mail.SmtpMail.cs
  3. //
  4. // Author:
  5. // Lawrence Pit ([email protected])
  6. // Per Arneng ([email protected]) (SmtpMail.Send)
  7. //
  8. using System;
  9. using System.Net;
  10. using System.IO;
  11. using System.Reflection;
  12. namespace System.Web.Mail
  13. {
  14. /// <remarks>
  15. /// </remarks>
  16. public class SmtpMail
  17. {
  18. private static string smtpServer = "localhost";
  19. // Constructor
  20. private SmtpMail ()
  21. {
  22. /* empty */
  23. }
  24. // Properties
  25. public static string SmtpServer {
  26. get { return smtpServer; }
  27. set { smtpServer = value; }
  28. }
  29. public static void Send (MailMessage message)
  30. {
  31. try {
  32. MailMessageWrapper messageWrapper = new MailMessageWrapper( message );
  33. SmtpClient smtp = new SmtpClient (smtpServer);
  34. smtp.Send (messageWrapper);
  35. smtp.Close ();
  36. } catch (SmtpException ex) {
  37. // LAMESPEC:
  38. // .NET sdk throws HttpException
  39. // for some reason so to be compatible
  40. // we have to do it to :(
  41. throw new HttpException (ex.Message);
  42. } catch (IOException ex) {
  43. throw new HttpException (ex.Message);
  44. } catch (FormatException ex) {
  45. throw new HttpException (ex.Message);
  46. }
  47. }
  48. public static void Send (string from, string to, string subject, string messageText)
  49. {
  50. MailMessage message = new MailMessage ();
  51. message.From = from;
  52. message.To = to;
  53. message.Subject = subject;
  54. message.Body = messageText;
  55. Send (message);
  56. }
  57. }
  58. } //namespace System.Web.Mail