Kaynağa Gözat

Mail interfaces, not yet sending out mails though

svn path=/trunk/mcs/; revision=4063
Lawrence Pit 24 yıl önce
ebeveyn
işleme
cbfe3aa7d3

+ 4 - 0
mcs/class/System.Web/ChangeLog

@@ -1,3 +1,7 @@
+2002-04-26  Lawrence Pit <[email protected]>
+
+	* Added directory: System.Web.Mail
+	
 2002-04-10  Patrik Torstensson <[email protected]>
 
 	* System.Web -- Assembly build.

+ 8 - 0
mcs/class/System.Web/System.Web.Mail/ChangeLog

@@ -0,0 +1,8 @@
+2002-04-26  Lawrence Pit <[email protected]>
+
+	* MailAttachment.cs: Implemented
+	* MailEncoding.cs: Implemented
+	* MailFormat.cs: Implemented
+	* MailMessage.cs: Implemented
+	* MailPriority.cs: Implemented
+	* SmtpMail.cs: Stubbed

+ 44 - 0
mcs/class/System.Web/System.Web.Mail/MailAttachment.cs

@@ -0,0 +1,44 @@
+//
+// System.Web.Mail.MailAttachment.cs
+//
+// Author:
+//    Lawrence Pit ([email protected])
+//
+
+namespace System.Web.Mail
+{
+	public class MailAttachment
+	{
+		private string filename;
+		private MailEncoding encoding;
+		
+		public MailAttachment (string filename) : 
+			this (filename, MailEncoding.Base64) 
+		{
+		}
+		
+		public MailAttachment (string filename, MailEncoding encoding) 
+		{
+			this.filename = filename;
+			this.encoding = encoding;
+			try {
+				System.IO.File.OpenRead (filename).Close ();
+			} catch (Exception) {
+				throw new System.Web.HttpException ("Cannot find file: " + filename);
+			}			
+		}
+		
+		// Properties
+		public string Filename 
+		{
+			get { return filename; } 
+		}
+		
+		public MailEncoding Encoding 
+		{
+			get { return encoding; } 
+		}		
+	
+	}
+	
+} //namespace System.Web.Mail

+ 26 - 0
mcs/class/System.Web/System.Web.Mail/MailEncoding.cs

@@ -0,0 +1,26 @@
+//
+// System.Web.Mail.MailEncoding.cs
+//
+// Author:
+//    Lawrence Pit ([email protected])
+//
+
+namespace System.Web.Mail 
+{
+
+	/// <summary>
+	/// </summary>
+	public enum MailEncoding 
+	{
+
+		/// <summary>
+		/// </summary>
+		UUEncode = 0,
+
+		/// <summary>
+		/// </summary>
+		Base64 = 1
+
+	} 
+	
+} //namespace System.Web.Mail

+ 26 - 0
mcs/class/System.Web/System.Web.Mail/MailFormat.cs

@@ -0,0 +1,26 @@
+//
+// System.Web.Mail.MailFormat.cs
+//
+// Author:
+//    Lawrence Pit ([email protected])
+//
+
+namespace System.Web.Mail 
+{
+
+	/// <summary>
+	/// </summary>
+	public enum MailFormat 
+	{
+
+		/// <summary>
+		/// </summary>
+		Text = 0,
+	
+		/// <summary>
+		/// </summary>
+		Html = 1
+
+	} 
+	
+} //namespace System.Web.Mail

+ 106 - 0
mcs/class/System.Web/System.Web.Mail/MailMessage.cs

@@ -0,0 +1,106 @@
+//
+// System.Web.Mail.MailMessage.cs
+//
+// Author:
+//    Lawrence Pit ([email protected])
+//
+
+using System;
+using System.Collections;
+using System.Collections.Specialized;
+using System.Text;
+
+namespace System.Web.Mail
+{
+	/// <remarks>
+	/// </remarks>
+	public class MailMessage
+	{
+		private ArrayList attachments;
+		private string bcc;
+		private string body;
+		private Encoding bodyEncoding;
+		private MailFormat bodyFormat;
+		private string cc;		
+		private string from;
+		private ListDictionary headers;
+		private MailPriority priority;
+		private string subject;
+		private string to;
+		private string urlContentBase;
+		private string urlContentLocation;
+		
+		// Constructor		
+		public MailMessage ()
+		{
+			attachments = new ArrayList (8);
+			headers = new ListDictionary ();
+		}		
+	
+		// Properties
+		public IList Attachments {
+			get { return (IList) attachments; }
+		}		
+		
+		public string Bcc {
+			get { return bcc; } 
+			set { bcc = value; }
+		}
+	
+		public string Body {
+			get { return body; } 
+			set { body = value; }
+		}
+
+		public Encoding BodyEncoding {
+			get { return bodyEncoding; } 
+			set { bodyEncoding = value; }
+		}
+
+		public MailFormat BodyFormat {
+			get { return bodyFormat; } 
+			set { bodyFormat = value; }
+		}		
+
+		public string Cc {
+			get { return cc; } 
+			set { cc = value; }
+		}
+
+		public string From {
+			get { return from; } 
+			set { from = value; }
+		}
+
+		public IDictionary Headers {
+			get { return (IDictionary) headers; }
+		}
+		
+		public MailPriority Priority {
+			get { return priority; } 
+			set { priority = value; }
+		}
+		
+		public string Subject {
+			get { return subject; } 
+			set { subject = value; }
+		}
+
+		public string To {
+			get { return to; }   
+			set { to = value; }
+		}
+
+		public string UrlContentBase {
+			get { return urlContentBase; } 
+			set { urlContentBase = value; }
+		}
+
+		public string UrlContentLocation {
+			get { return urlContentLocation; } 
+			set { urlContentLocation = value; }
+		}
+
+	}
+	
+} //namespace System.Web.Mail

+ 30 - 0
mcs/class/System.Web/System.Web.Mail/MailPriority.cs

@@ -0,0 +1,30 @@
+//
+// System.Web.Mail.MailPriority.cs
+//
+// Author:
+//    Lawrence Pit ([email protected])
+//
+
+namespace System.Web.Mail 
+{
+
+	/// <summary>
+	/// </summary>
+	public enum MailPriority 
+	{
+
+		/// <summary>
+		/// </summary>
+		Normal = 0,
+		
+		/// <summary>
+		/// </summary>
+		Low = 1,
+
+		/// <summary>
+		/// </summary>
+		High = 2
+
+	} 
+	
+} //namespace System.Web.Mail

+ 75 - 0
mcs/class/System.Web/System.Web.Mail/SmtpMail.cs

@@ -0,0 +1,75 @@
+//
+// System.Web.Mail.SmtpMail.cs
+//
+// Author:
+//    Lawrence Pit ([email protected])
+//
+//
+
+using System;
+using System.Net;
+using System.Reflection;
+
+namespace System.Web.Mail
+{
+	/// <remarks>
+	/// </remarks>
+	public class SmtpMail
+	{
+		private static string smtpServer;
+		
+		// Constructor		
+		private SmtpMail ()
+		{
+			/* empty */
+		}		
+
+		// Properties
+		public static string SmtpServer {
+			get { return smtpServer; } 
+			set { smtpServer = value; }
+		}
+		
+		[MonoTODO]
+		public static void Send (MailMessage message) 
+		{
+			// delegate work to loosly coupled component Mono.Mail
+			
+			// Mono.Mail.Smtp.SmtpSender.Send (smtpServer, message);	
+			
+			// NOTE: Mono.Mail is work in progress, and could be replaced by 
+			// another component. For now:
+			
+			throw new NotImplementedException("Mono.Mail component is work in progress");
+
+			try {
+				// TODO: possibly cache ctor info object..
+				Type stype = Type.GetType ("Mono.Mail.Smtp.SmtpSender");
+				if (stype == null) {
+					throw new Exception ("You must have Mono.Mail installed to send mail.");
+				}
+				Type[] types = new Type[2];
+				types[0] = typeof (string);
+				types[1] = message.GetType ();
+				ConstructorInfo cinfo = 
+					stype.GetConstructor(BindingFlags.Instance | BindingFlags.Public, null,
+						CallingConventions.HasThis, types, null);
+				cinfo.Invoke (new object[] {smtpServer, message});
+			} catch (Exception) {
+				throw new Exception ("Unable to call Mono.Mail.Smtp.SmtpSender");
+			}
+		}
+		
+		public static void Send (string from, string to, string subject, string messageText) 
+		{
+			MailMessage message = new MailMessage ();
+			message.From = from;
+			message.To = to;
+			message.Subject = subject;
+			message.Body = messageText;
+			Send (message);
+		}
+	
+	}
+	
+} //namespace System.Web.Mail