2 // System.Net.Mail.MailMessage.cs
5 // Tim Coleman (tim@timcoleman.com)
7 // Copyright (C) Tim Coleman, 2004
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using System.Collections.Specialized;
34 using System.Globalization;
35 using System.Net.Mime;
38 namespace System.Net.Mail {
40 public class MailMessage : IDisposable
44 AlternateViewCollection alternateViews;
45 AttachmentCollection attachments;
46 MailAddressCollection bcc;
48 MailPriority priority;
49 MailAddress replyTo, sender;
50 DeliveryNotificationOptions deliveryNotificationOptions;
51 MailAddressCollection cc;
53 NameValueCollection headers;
54 MailAddressCollection to;
56 Encoding subjectEncoding;
57 ContentType bodyContentType;
67 [MonoTODO ("FormatException")]
68 public MailMessage (MailAddress from, MailAddress to)
70 if (from == null || to == null)
71 throw new ArgumentNullException ();
75 this.to = new MailAddressCollection ();
78 alternateViews = new AlternateViewCollection ();
79 attachments = new AttachmentCollection ();
80 bcc = new MailAddressCollection ();
81 cc = new MailAddressCollection ();
82 headers = new NameValueCollection ();
84 headers.Add ("MIME-Version", "1.0");
87 public MailMessage (string from, string to)
88 : this (new MailAddress (from), new MailAddress (to))
90 if (from == null || to == null)
91 throw new ArgumentNullException ();
94 public MailMessage (string from, string to, string subject, string body)
95 : this (new MailAddress (from), new MailAddress (to))
97 if (from == null || to == null)
98 throw new ArgumentNullException ();
103 #endregion // Constructors
107 public AlternateViewCollection AlternateViews {
108 get { return alternateViews; }
111 public AttachmentCollection Attachments {
112 get { return attachments; }
115 public MailAddressCollection Bcc {
121 set { body = value; }
124 internal ContentType BodyContentType {
126 if (bodyContentType == null)
127 bodyContentType = new ContentType ("text/plain; charset=us-ascii");
128 return bodyContentType;
132 public Encoding BodyEncoding {
133 get { return Encoding.GetEncoding (BodyContentType.CharSet); }
134 set { BodyContentType.CharSet = value.WebName; }
137 public MailAddressCollection CC {
141 public DeliveryNotificationOptions DeliveryNotificationOptions {
142 get { return deliveryNotificationOptions; }
143 set { deliveryNotificationOptions = value; }
146 public MailAddress From {
148 set { from = value; }
151 public NameValueCollection Headers {
152 get { return headers; }
155 public bool IsBodyHtml {
156 get { return String.Compare (BodyContentType.MediaType, "text/html", true, CultureInfo.InvariantCulture) == 0; }
159 BodyContentType.MediaType = "text/html";
161 BodyContentType.MediaType = "text/plain";
165 public MailPriority Priority {
166 get { return priority; }
167 set { priority = value; }
170 public MailAddress ReplyTo {
171 get { return replyTo; }
172 set { replyTo = value; }
175 public MailAddress Sender {
176 get { return sender; }
177 set { sender = value; }
180 public string Subject {
181 get { return subject; }
182 set { subject = value; }
185 public Encoding SubjectEncoding {
186 get { return subjectEncoding; }
187 set { subjectEncoding = value; }
190 public MailAddressCollection To {
194 #endregion // Properties
198 public void Dispose ()
201 GC.SuppressFinalize (this);
204 protected virtual void Dispose (bool disposing)
208 #endregion // Methods