EmailSettings.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using FastReport.Utils;
  5. namespace FastReport
  6. {
  7. /// <summary>
  8. /// Contains the email settings such as recipient(s) address, name, subject, message body.
  9. /// </summary>
  10. /// <remarks>
  11. /// </remarks>
  12. [TypeConverter(typeof(FastReport.TypeConverters.FRExpandableObjectConverter))]
  13. public class EmailSettings
  14. {
  15. #region Fields
  16. private string[] recipients;
  17. private string subject;
  18. private string message;
  19. #endregion
  20. #region Properties
  21. /// <summary>
  22. /// Gets or sets the recipient(s) email addresses.
  23. /// </summary>
  24. /// <remarks>
  25. /// This property contains one or several email addresses in the following form: "john@url.com".
  26. /// </remarks>
  27. public string[] Recipients
  28. {
  29. get { return recipients; }
  30. set { recipients = value; }
  31. }
  32. /// <summary>
  33. /// Gets or sets the message subject.
  34. /// </summary>
  35. public string Subject
  36. {
  37. get { return subject; }
  38. set { subject = value; }
  39. }
  40. /// <summary>
  41. /// Gets or sets the message body.
  42. /// </summary>
  43. public string Message
  44. {
  45. get { return message; }
  46. set { message = value; }
  47. }
  48. internal string RecipientsText
  49. {
  50. get
  51. {
  52. if (Recipients == null)
  53. return "";
  54. string result = "";
  55. foreach (string recipient in Recipients)
  56. {
  57. result += recipient + "\r\n";
  58. }
  59. return result.Substring(0, result.Length - 2);
  60. }
  61. set
  62. {
  63. if (String.IsNullOrEmpty(value))
  64. {
  65. recipients = null;
  66. return;
  67. }
  68. Recipients = value.Replace("\r\n", "\n").Split('\n');
  69. }
  70. }
  71. internal string FirstRecipient
  72. {
  73. get { return Recipients == null ? "" : Recipients[0]; }
  74. }
  75. internal string[] CCRecipients
  76. {
  77. get
  78. {
  79. if (Recipients == null || Recipients.Length == 1)
  80. return null;
  81. List<string> result = new List<string>();
  82. for (int i = 1; i < Recipients.Length; i++)
  83. {
  84. result.Add(Recipients[i]);
  85. }
  86. return result.ToArray();
  87. }
  88. }
  89. #endregion
  90. #region Public Methods
  91. /// <summary>
  92. /// Copies email settings from another source.
  93. /// </summary>
  94. /// <param name="source">Source to copy settings from.</param>
  95. public void Assign(EmailSettings source)
  96. {
  97. Recipients = source.Recipients;
  98. Subject = source.Subject;
  99. Message = source.Message;
  100. }
  101. /// <summary>
  102. /// Resets all settings to its default values.
  103. /// </summary>
  104. public void Clear()
  105. {
  106. recipients = null;
  107. subject = "";
  108. message = "";
  109. }
  110. internal void Serialize(FRWriter writer, EmailSettings c)
  111. {
  112. if (Recipients != c.Recipients)
  113. writer.WriteValue("EmailSettings.Recipients", Recipients);
  114. if (Subject != c.Subject)
  115. writer.WriteStr("EmailSettings.Subject", Subject);
  116. if (Message != c.Message)
  117. writer.WriteStr("EmailSettings.Message", Message);
  118. }
  119. #endregion
  120. /// <summary>
  121. /// Initializes a new instance of the <see cref="EmailSettings"/> class with default settings.
  122. /// </summary>
  123. public EmailSettings()
  124. {
  125. Clear();
  126. }
  127. }
  128. }