PageRenderTime 57ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/ThinkEmailFomatter/Models/BusinessObjects/EmailContext.cs

https://bitbucket.org/nicdao/frg-think-emailformatter
C# | 70 lines | 55 code | 9 blank | 6 comment | 0 complexity | 1f142bddbdac6db256dc9f6c421fa98a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.ComponentModel.DataAnnotations;
  6. using System.Configuration;
  7. using System.Net.Mail;
  8. namespace ThinkEmailFormatter.Models
  9. {
  10. public class EmailContext
  11. {
  12. /// <summary>
  13. /// Defines the URL where images are publicly accessible
  14. /// </summary>
  15. public string AttachmentsRootUrl { get; set; }
  16. public string Host
  17. {
  18. get
  19. {
  20. return _smtpServer.Host;
  21. }
  22. set
  23. {
  24. _smtpServer.Host = value;
  25. }
  26. }
  27. public string EmailHtmlBody { get; set; }
  28. private SmtpClient _smtpServer;
  29. public EmailContext()
  30. {
  31. _smtpServer = new SmtpClient();
  32. }
  33. /// <summary>
  34. /// Semicolon separated string contains all recipient emails
  35. /// </summary>
  36. [Required(ErrorMessage="At leat one recipient is required")]
  37. [Display(Name = "To")]
  38. public string Recipients { get; set; }
  39. public string Subject { get; set; }
  40. public string TemplateName { get; set; }
  41. public string FromEmail { get; set; }
  42. public ThinkTransactionData ThinkData { get; set; }
  43. public void HtmlSend()
  44. {
  45. var mail = new MailMessage(FromEmail, Recipients)
  46. {
  47. Subject = Subject,
  48. Body = EmailHtmlBody,
  49. IsBodyHtml = true
  50. };
  51. _smtpServer.Send(mail);
  52. }
  53. public void AbsorbContent(EmailContext emailContext)
  54. {
  55. Recipients = emailContext.Recipients;
  56. Subject = emailContext.Subject;
  57. EmailHtmlBody = emailContext.EmailHtmlBody;
  58. TemplateName = emailContext.TemplateName;
  59. }
  60. }
  61. }