Tim Coleman <tim@timcoleman.com>
authorTim Coleman <tim@mono-cvs.ximian.com>
Sat, 4 Sep 2004 19:49:50 +0000 (19:49 -0000)
committerTim Coleman <tim@mono-cvs.ximian.com>
Sat, 4 Sep 2004 19:49:50 +0000 (19:49 -0000)
        * Attachment.cs MailAddress.cs MailMessage.cs SendCompletedEventHandler.cs
        * SmtpAccess.cs SmtpClient.cs SmtpException.cs SmtpStatusCode.cs:
                New class stubs for 2.0

svn path=/trunk/mcs/; revision=33343

mcs/class/System/System.Net.Mail/Attachment.cs [new file with mode: 0755]
mcs/class/System/System.Net.Mail/ChangeLog [new file with mode: 0644]
mcs/class/System/System.Net.Mail/MailAddress.cs [new file with mode: 0755]
mcs/class/System/System.Net.Mail/MailMessage.cs [new file with mode: 0755]
mcs/class/System/System.Net.Mail/SendCompletedEventHandler.cs [new file with mode: 0755]
mcs/class/System/System.Net.Mail/SmtpAccess.cs [new file with mode: 0755]
mcs/class/System/System.Net.Mail/SmtpClient.cs [new file with mode: 0755]
mcs/class/System/System.Net.Mail/SmtpException.cs [new file with mode: 0755]
mcs/class/System/System.Net.Mail/SmtpStatusCode.cs [new file with mode: 0755]

diff --git a/mcs/class/System/System.Net.Mail/Attachment.cs b/mcs/class/System/System.Net.Mail/Attachment.cs
new file mode 100755 (executable)
index 0000000..a21e08a
--- /dev/null
@@ -0,0 +1,202 @@
+//
+// System.Net.Mail.Attachment.cs
+//
+// Author:
+//     Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System.IO;
+using System.Net.Mime;
+using System.Text;
+
+namespace System.Net.Mail {
+       public class Attachment : IDisposable
+       {
+               #region Fields
+
+               ContentType contentType;
+               Encoding encoding;
+
+               ContentDisposition contentDisposition;
+               Stream contentStream;
+               string contentString;
+               string name;
+               TransferEncoding transferEncoding;
+
+               #endregion // Fields
+
+               #region Constructors
+
+               public Attachment ()
+               {
+                       contentDisposition = new ContentDisposition ("attachment"); 
+                       contentType = new ContentType ();
+               }
+
+               public Attachment (string contentString)
+               {
+                       SetContent (contentString);
+               }
+
+               public Attachment (Stream contentStream, ContentType contentType)
+               {
+                       SetContent (contentStream);
+                       this.contentType = contentType;
+               }
+
+               public Attachment (Stream contentStream, string name)
+               {
+                       SetContent (contentStream, name);
+               }
+
+               public Attachment (string contentString, string mediaType)
+               {
+                       SetContent (contentString, mediaType);
+               }
+
+               public Attachment (Stream contentStream, string name, string mediaType)
+               {
+                       SetContent (contentStream, name, mediaType);
+               }
+
+               public Attachment (string contentString, string mediaType, Encoding encoding)
+               {
+                       SetContent (contentString, mediaType, encoding);
+               }
+
+
+               #endregion // Constructors
+
+               #region Properties
+
+               [MonoTODO]
+               public ContentDisposition ContentDisposition {
+                       get { return contentDisposition; }
+               }
+
+               public Stream ContentStream {
+                       get { return contentStream; }
+               }
+
+               public string ContentString {
+                       get { return contentString; }
+               }
+
+               public Encoding ContentStringEncoding {
+                       get { return encoding; }
+               }
+
+               public ContentType ContentType {
+                       get { return contentType; }
+               }
+
+               [MonoTODO]
+               public string FileName {
+                       get { throw new NotImplementedException (); }
+               }
+
+               public string Name {
+                       get { return contentType.Name; }
+                       set { 
+                               if (value == null)
+                                       throw new ArgumentNullException ();
+                               if (value.Equals (""))
+                                       throw new ArgumentException ();
+                               contentType.Name = value;
+                       }
+               }
+
+               public TransferEncoding TransferEncoding {
+                       get { return transferEncoding; }
+                       set { transferEncoding = value; }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+
+               [MonoTODO]
+               public void Dispose ()
+               {
+               }
+
+               public void SetContent (Stream contentStream)
+               {
+                       this.contentStream = contentStream;
+                       contentType.MediaType = MediaTypeNames.Application.Octet;
+                       contentType.CharSet = null;
+                       transferEncoding = TransferEncoding.Base64;
+               }
+
+               public void SetContent (string contentString)
+               {
+                       SetContent (contentString, MediaTypeNames.Text.Plain, Encoding.Default);
+               }
+
+               public void SetContent (Stream contentStream, string name)
+               {
+                       SetContent (contentStream);
+                       contentType.Name = name;
+               }
+
+               public void SetContent (string contentString, string mediaType)
+               {
+                       SetContent (contentString, mediaType, Encoding.Default);
+               }
+
+               public void SetContent (Stream contentStream, string name, string mediaType)
+               {
+                       SetContent (contentStream, name);
+                       contentType.MediaType = mediaType;
+               }
+
+               public void SetContent (string contentString, string mediaType, Encoding encoding)
+               {
+                       contentType.MediaType = mediaType;
+                       contentType.CharSet = encoding.WebName;
+
+                       transferEncoding = TransferEncoding.QuotedPrintable;
+
+                       contentStream = new MemoryStream ();
+                       StreamWriter sw = new StreamWriter (contentStream);
+                       sw.Write (contentString);
+                       sw.Flush ();
+                       sw.Close ();
+
+                       contentStream.Position = 0;
+               }
+
+               public void SetContent (string contentString, string mediaType, Encoding encoding, TransferEncoding transferEncoding)
+               {
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif // NET_2_0
diff --git a/mcs/class/System/System.Net.Mail/ChangeLog b/mcs/class/System/System.Net.Mail/ChangeLog
new file mode 100644 (file)
index 0000000..66481b8
--- /dev/null
@@ -0,0 +1,4 @@
+Tim Coleman  <tim@timcoleman.com>
+       * Attachment.cs MailAddress.cs MailMessage.cs SendCompletedEventHandler.cs
+       * SmtpAccess.cs SmtpClient.cs SmtpException.cs SmtpStatusCode.cs:
+               New class stubs for 2.0
diff --git a/mcs/class/System/System.Net.Mail/MailAddress.cs b/mcs/class/System/System.Net.Mail/MailAddress.cs
new file mode 100755 (executable)
index 0000000..7e0d264
--- /dev/null
@@ -0,0 +1,108 @@
+//
+// System.Net.Mail.MailAddress.cs
+//
+// Author:
+//     Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System.Text;
+
+namespace System.Net.Mail {
+       public class MailAddress 
+       {
+               #region Fields
+
+               string address;
+               string displayName;
+               Encoding displayNameEncoding;
+
+               #endregion // Fields
+
+               #region Constructors
+
+               public MailAddress (string address)
+               {
+                       this.address = address;
+               }
+
+               public MailAddress (string address, string displayName)
+               {
+                       this.address = address;
+                       this.displayName = displayName;
+               }
+
+               public MailAddress (string address, string name, Encoding displayNameEncoding)
+               {
+                       this.address = address;
+                       this.displayName = displayName;
+                       this.displayNameEncoding = displayNameEncoding;
+               }
+
+               #endregion // Constructors
+
+               #region Properties
+
+               public string Address { 
+                       get { return address; }
+               }
+
+               public string DisplayName {
+                       get { return displayName; }
+               }
+
+               public string Host {
+                       get { return Address.Substring (address.IndexOf ("@") + 1); }
+               }
+
+               public string User {
+                       get { return Address.Substring (0, address.IndexOf ("@")); }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+
+               public override string ToString ()
+               {
+                       StringBuilder sb = new StringBuilder ();
+                       if (DisplayName != null && DisplayName.Length > 0) {
+                               sb.Append (DisplayName);
+                               sb.Append (" ");
+                       }
+                       sb.Append ("<");
+                       sb.Append (Address);
+                       sb.Append (">");
+
+                       return sb.ToString ();
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif // NET_2_0
diff --git a/mcs/class/System/System.Net.Mail/MailMessage.cs b/mcs/class/System/System.Net.Mail/MailMessage.cs
new file mode 100755 (executable)
index 0000000..fae3a41
--- /dev/null
@@ -0,0 +1,166 @@
+//
+// System.Net.Mail.MailMessage.cs
+//
+// Author:
+//     Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System.Collections.Generic;
+using System.Collections.Specialized;
+using System.Net.Mime;
+using System.Text;
+
+namespace System.Net.Mail {
+       [MonoTODO]
+       public class MailMessage : IDisposable
+       {
+               #region Fields
+
+               Collection<Attachment> alternateViews;
+               Collection<Attachment> attachments;
+               Collection<MailAddress> bcc;
+               string body;
+               ContentType bodyContentType;
+               Encoding bodyEncoding;
+               Collection<MailAddress> cc;
+               MailAddress from;
+               NameValueCollection headers;
+               Collection<MailAddress> to;
+               string subject;
+               Encoding subjectEncoding;
+
+               #endregion // Fields
+
+               #region Constructors
+
+               public MailMessage (MailAddress from, MailAddress to)
+               {
+                       From = from;
+
+                       this.to = new Collection<MailAddress> ();
+                       this.to.Add (to);
+
+                       alternateViews = new Collection<Attachment> ();
+                       attachments = new Collection<Attachment> ();
+                       bcc = new Collection<MailAddress> ();
+                       cc = new Collection<MailAddress> ();
+                       bodyContentType = new ContentType (MediaTypeNames.Application.Octet);
+                       headers = new NameValueCollection ();
+               }
+
+               public MailMessage (string from, string to)
+                       : this (new MailAddress (from), new MailAddress (to))
+               {
+               }
+
+               public MailMessage (string from, string to, string subject, string body)
+                       : this (new MailAddress (from), new MailAddress (to))
+               {
+                       Body = body;
+                       Subject = subject;
+               }
+
+               #endregion // Constructors
+
+               #region Properties
+
+               public Collection<Attachment> AlternateViews {
+                       get { return alternateViews; }
+               }
+
+               public Collection<Attachment> Attachments {
+                       get { return attachments; }
+               }
+
+               public Collection<MailAddress> Bcc {
+                       get { return bcc; }
+               }
+
+               public string Body {
+                       get { return body; }
+                       set { body = value; }
+               }
+
+               public ContentType BodyContentType {
+                       get { return bodyContentType; }
+               }
+
+               public Encoding BodyEncoding {
+                       get { return bodyEncoding; }
+                       set { 
+                               bodyEncoding = value;
+                               bodyContentType.CharSet = value.WebName; 
+                       }
+               }
+
+               public Collection<MailAddress> CC {
+                       get { return cc; }
+               }
+
+               public MailAddress From {
+                       get { return from; }
+                       set { from = value; }
+               }
+
+               public NameValueCollection Headers {
+                       get { return headers; }
+               }
+
+               public string Subject {
+                       get { return subject; }
+                       set { subject = value; }
+               }
+
+               public Encoding SubjectEncoding {
+                       get { return subjectEncoding; }
+                       set { subjectEncoding = value; }
+               }
+
+               public Collection<MailAddress> To {
+                       get { return to; }
+               }
+
+               #endregion // Properties
+
+               #region Methods
+
+               [MonoTODO]
+               public void Dispose ()
+               {
+               }
+
+               [MonoTODO]
+               ~MailMessage ()
+               {
+               }
+
+               #endregion // Methods
+       }
+}
+
+#endif // NET_2_0
diff --git a/mcs/class/System/System.Net.Mail/SendCompletedEventHandler.cs b/mcs/class/System/System.Net.Mail/SendCompletedEventHandler.cs
new file mode 100755 (executable)
index 0000000..76c905d
--- /dev/null
@@ -0,0 +1,40 @@
+//
+// System.Net.Mail.SendCompletedEventHandler.cs
+//
+// Author:
+//     Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System.ComponentModel;
+
+namespace System.Net.Mail 
+{
+       public delegate void SendCompletedEventHandler (object sender, AsyncCompletedEventArgs e);
+}
+
+#endif // NET_2_0
diff --git a/mcs/class/System/System.Net.Mail/SmtpAccess.cs b/mcs/class/System/System.Net.Mail/SmtpAccess.cs
new file mode 100755 (executable)
index 0000000..35a7c75
--- /dev/null
@@ -0,0 +1,41 @@
+//
+// System.Net.Mail.SmtpAccess.cs
+//
+// Author:
+//     Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+namespace System.Net.Mail {
+       public enum SmtpAccess
+       {
+               Connect = 0x1,
+               None = 0x0
+       }
+}
+
+#endif // NET_2_0
diff --git a/mcs/class/System/System.Net.Mail/SmtpClient.cs b/mcs/class/System/System.Net.Mail/SmtpClient.cs
new file mode 100755 (executable)
index 0000000..8bb62b2
--- /dev/null
@@ -0,0 +1,359 @@
+//
+// System.Net.Mail.SmtpClient.cs
+//
+// Author:
+//     Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Text;
+
+namespace System.Net.Mail {
+       public class SmtpClient : IDisposable //, IGetContextAwareResult
+       {
+               #region Fields
+
+               string host;
+               int port;
+               int timeout;
+               ICredentialsByHost credentials;
+               bool useDefaultCredentials;
+               TcpClient client;
+
+               const string MimeVersion = "1.0 (produced by Mono System.Net.Mail.SmtpClient)";
+
+               #endregion // Fields
+
+               #region Constructors
+
+               public SmtpClient ()
+                       : this (null, 0)
+               {
+               }
+
+               public SmtpClient (string host)
+                       : this (host, 0)
+               {
+               }
+
+               [MonoTODO ("Load default settings from configuration.")]
+               public SmtpClient (string host, int port)
+               {
+                       Host = host;
+                       Port = port;
+               }
+
+               #endregion // Constructors
+
+               #region Properties
+
+               public ICredentialsByHost Credentials {
+                       get { return credentials; }
+                       set { credentials = value; }
+               }
+
+               public string Host {
+                       get { return host; }
+                       set { host = value; }
+               }
+
+               public int Port {
+                       get { return port; }
+                       [MonoTODO ("Check to make sure an email is not being sent.")]
+                       set { 
+                               if (value <= 0)
+                                       throw new ArgumentOutOfRangeException ();
+                               port = value; 
+                       }
+               }
+
+               [MonoTODO]
+               public ServicePoint ServicePoint {
+                       get { throw new NotImplementedException (); }
+               }
+
+               public int Timeout {
+                       get { return timeout; }
+                       [MonoTODO ("Check to make sure an email is not being sent.")]
+                       set { 
+                               if (value <= 0)
+                                       throw new ArgumentOutOfRangeException ();
+                               timeout = value; 
+                       }
+               }
+
+               public bool UseDefaultCredentials {
+                       get { return useDefaultCredentials; }
+                       set { useDefaultCredentials = value; }
+               }
+
+               #endregion // Properties
+
+               #region Events 
+
+               public event SendCompletedEventHandler SendCompleted;
+
+               #endregion // Events 
+
+               #region Methods
+
+               [MonoTODO]
+               public void Dispose ()
+               {
+               }
+
+               private bool IsError (SmtpResponse status)
+               {
+                       return ((int) status.StatusCode) >= 400;
+               }
+
+               protected void OnSendCompleted (AsyncCompletedEventArgs e)
+               {
+                       if (SendCompleted != null)
+                               SendCompleted (this, e);
+               }
+
+               [MonoTODO ("Need to work on message attachments.")]
+               public void Send (MailMessage message)
+               {
+                       SmtpResponse status;
+                       Sender sender = new Sender (Host, Port);
+
+                       string to = CreateAddressList (message.To);
+                       string cc = CreateAddressList (message.CC);
+                       string bcc = CreateAddressList (message.Bcc);
+
+                       Console.WriteLine (to);
+
+                       status = sender.Read ();
+                       if (IsError (status))
+                               throw new SmtpException (status.StatusCode);
+
+                       status = sender.SendCommand (Command.Helo, Dns.GetHostName ());
+                       if (IsError (status))
+                               throw new SmtpException (status.StatusCode);
+
+                       status = sender.SendCommand (Command.MailFrom, message.From.Address);
+                       if (IsError (status))
+                               throw new SmtpException (status.StatusCode);
+
+                       status = sender.SendCommand (Command.RcptTo, to);
+                       if (IsError (status))
+                               throw new SmtpException (status.StatusCode);
+
+                       status = sender.SendCommand (Command.Data);
+                       if (IsError (status))
+                               throw new SmtpException (status.StatusCode);
+
+                       sender.SendHeader (HeaderName.From, message.From.ToString ());
+                       sender.SendHeader (HeaderName.To, to);
+                       
+                       if (cc != null)
+                               sender.SendHeader (HeaderName.Cc, cc);
+
+                       if (bcc != null)
+                               sender.SendHeader (HeaderName.Bcc, bcc);
+
+                       sender.SendHeader (HeaderName.Subject, message.Subject);
+                       sender.SendHeader (HeaderName.MimeVersion, MimeVersion);
+                       sender.SendHeader (HeaderName.ContentType, "");
+                       sender.SendHeader (HeaderName.ContentTransferEncoding, "");
+
+                       sender.Send ("");
+                       sender.Send (message.Body);
+                       sender.Send (".");
+
+                       status = sender.Read ();
+                       if (IsError (status))
+                               throw new SmtpException (status.StatusCode);
+
+                       status = sender.SendCommand (Command.Quit);
+
+                       sender.Close ();
+               }
+
+               private string CreateAddressList (Collection<MailAddress> addressList)
+               {
+                       if (addressList.Count > 0) {
+                               StringBuilder sb = new StringBuilder ();
+                               for (int i = 0; i < addressList.Count; i += 1) {
+                                       if (sb.Length > 0)
+                                               sb.Append (", ");
+                                       sb.Append (addressList [i].ToString ());
+                               }
+                               return sb.ToString ();
+                       }
+
+                       return null;
+               }
+
+               public void Send (string from, string to, string subject, string body)
+               {
+                       Send (new MailMessage (from, to, subject, body));
+               }
+
+               [MonoTODO]
+               public void SendAsync (MailMessage message, object userToken)
+               {
+                       Send (message);
+                       OnSendCompleted (new AsyncCompletedEventArgs (null, false, userToken));
+               }
+
+               public void SendAsync (string from, string to, string subject, string body, object userToken)
+               {
+                       SendAsync (new MailMessage (from, to, subject, body), userToken);
+               }
+
+               [MonoTODO]
+               public void SendAsyncCancel ()
+               {
+                       throw new NotImplementedException ();
+               }
+
+/*
+               [MonoTODO]
+               private sealed ContextAwareResult IGetContextAwareResult.GetContextAwareResult ()
+               {
+                       throw new NotImplementedException ();
+               }
+*/
+               #endregion // Methods
+
+               // The Command struct is used to store constant string values representing SMTP commands.
+               private struct Command {
+                       public const string Data = "DATA";
+                       public const string Helo = "HELO";
+                       public const string MailFrom = "MAIL FROM:";
+                       public const string Quit = "QUIT";
+                       public const string RcptTo = "RCPT TO:";
+               }
+
+               // The HeaderName struct is used to store constant string values representing mail headers.
+               private struct HeaderName {
+                       public const string ContentTransferEncoding = "Content-Transfer-Encoding";
+                       public const string ContentType = "Content-Type";
+                       public const string Bcc = "Bcc";
+                       public const string Cc = "Cc";
+                       public const string From = "From";
+                       public const string Subject = "Subject";
+                       public const string To = "To";
+                       public const string MimeVersion = "MIME-Version";
+               }
+
+               // This object encapsulates the status code and description of an SMTP response.
+               private struct SmtpResponse {
+                       public SmtpStatusCode StatusCode;
+                       public string Description;
+               }
+
+               // The Sender class is used to manage sending information to the SMTP server.
+               private class Sender
+               {
+                       #region Fields
+
+                       TcpClient client;
+                       NetworkStream stream;
+                       StreamWriter writer;
+                       StreamReader reader;
+
+                       #endregion // Fields
+
+                       #region Constructors
+
+                       public Sender (String host, int port)
+                       {
+                               client = new TcpClient (host, port);
+                               stream = client.GetStream ();
+                               writer = new StreamWriter (stream);
+                               reader = new StreamReader (stream);
+                       }
+
+                       #endregion // Constructors
+
+                       #region Methods
+
+                       public void Close ()
+                       {
+                               writer.Close ();
+                               reader.Close ();
+                               stream.Close ();
+                               client.Close ();
+                       }
+
+                       public void Send (string data)
+                       {
+                               writer.WriteLine (data);
+                               writer.Flush ();
+                       }
+
+                       public SmtpResponse SendCommand (string command)
+                       {
+                               writer.WriteLine (command);
+                               writer.Flush ();
+                               return Read ();
+                       }
+
+                       public SmtpResponse SendCommand (string command, string data)
+                       {
+                               SmtpResponse response;
+                               writer.Write (command);
+                               writer.Write (" ");
+                               Send (data);
+
+                               return Read ();
+                       }
+
+                       public void SendHeader (string name, string value)
+                       {
+                               Send (String.Format ("{0}: {1}", name, value));
+                       }
+
+                       public SmtpResponse Read ()
+                       {
+                               SmtpResponse response;
+
+                               char[] buf = new char [3];
+                               reader.Read (buf, 0, 3);
+                               reader.Read ();
+
+                               response.StatusCode = (SmtpStatusCode) Int32.Parse (new String (buf));
+                               response.Description = reader.ReadLine ();
+
+                               return response;
+                       }
+
+                       #endregion // Methods
+               }
+       }
+}
+
+#endif // NET_2_0
diff --git a/mcs/class/System/System.Net.Mail/SmtpException.cs b/mcs/class/System/System.Net.Mail/SmtpException.cs
new file mode 100755 (executable)
index 0000000..b2f2b8f
--- /dev/null
@@ -0,0 +1,89 @@
+//
+// System.Net.Mail.SmtpException.cs
+//
+// Author:
+//     Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System.Runtime.Serialization;
+
+namespace System.Net.Mail {
+       public class SmtpException : Exception
+       {
+               #region Fields
+
+               SmtpStatusCode statusCode;
+
+               #endregion // Fields
+
+               #region Constructors
+
+               public SmtpException ()
+               {
+               }
+
+               public SmtpException (SmtpStatusCode statusCode)
+               {
+                       StatusCode = statusCode;
+               }
+
+               public SmtpException (string message)
+                       : base (message)
+               {
+               }
+
+               public SmtpException (SerializationInfo info, StreamingContext context)
+                       : base (info, context)
+               {
+               }
+
+               public SmtpException (SmtpStatusCode statusCode, string message)
+                       : base (message)
+               {
+                       StatusCode = statusCode;
+               }
+
+               public SmtpException (string message, Exception innerException)
+                       : base (message, innerException)
+               {
+               }
+
+               #endregion // Constructors
+
+               #region Properties
+
+               public SmtpStatusCode StatusCode {
+                       get { return statusCode; }
+                       set { statusCode = value; }
+               }
+
+               #endregion // Properties
+       }
+}
+
+#endif // NET_2_0
diff --git a/mcs/class/System/System.Net.Mail/SmtpStatusCode.cs b/mcs/class/System/System.Net.Mail/SmtpStatusCode.cs
new file mode 100755 (executable)
index 0000000..6087cf4
--- /dev/null
@@ -0,0 +1,63 @@
+//
+// System.Net.Mail.SmtpStatusCode.cs
+//
+// Author:
+//     Tim Coleman (tim@timcoleman.com)
+//
+// Copyright (C) Tim Coleman, 2004
+//
+
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+namespace System.Net.Mail {
+       public enum SmtpStatusCode
+       {
+               BadCommandSequence = 503,
+               CannotVerifyUserWillAttemptDelivery = 252,
+               ClientNotPermitted = 454,
+               CommandNotImplemented = 502,
+               CommandParameterNotImplemented = 504,
+               CommandUnrecognized = 500,
+               ExceededStorageAllocation = 552,
+               GeneralFailure = -1,
+               HelpMessage = 214,
+               InsufficientStorage = 452,
+               LocalErrorInProcessing = 451,
+               MailboxBusy = 450,
+               MailboxNameNotAllowed = 553,
+               MailboxUnavailable = 550,
+               OK = 250,
+               ServiceClosingTransmissionChannel = 221,
+               ServiceNotAvailable = 421,
+               ServiceReady = 220,
+               StartMailInput = 354,
+               SyntaxError = 501,
+               SystemStatus = 211,
+               TransactionFailed = 554,
+               UserNotLocalTryAlternatePath = 551,
+               UserNotLocalWillForward = 251
+       }
+}
+
+#endif // NET_2_0