Added RedirectUsingNamedRoute
[castle.git] / Components / EmailSender / Castle.Components.Common.EmailSender / MessageAttachment.cs
blob527f95126e5eb6de11b3fece395ce7076db943d0
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Components.Common.EmailSender
17 using System;
18 using System.IO;
20 public enum AttachmentEncoding
22 Base64,
23 UUEncode
26 /// <summary>
27 /// Represents a file attachment
28 /// </summary>
29 public class MessageAttachment
31 private String fileName;
32 private readonly String mediaType;
33 private readonly Stream stream;
35 /// <summary>
36 /// Creates a new attachment
37 /// </summary>
38 /// <param name="mediaType">Look at System.Net.Mimie.MediaTypeNames for help.</param>
39 /// <param name="fileName">Path to the file.</param>
40 public MessageAttachment(String mediaType, String fileName)
42 this.mediaType = mediaType;
44 if (fileName == null) throw new ArgumentNullException("fileName");
46 FileInfo info = new FileInfo(fileName);
48 if (!info.Exists) throw new ArgumentException("The specified file does not exists", "fileName");
50 this.fileName = fileName;
53 /// <summary>
54 /// Creates a new attachment
55 /// </summary>
56 /// <param name="mediaType">Look at System.Net.Mime.MediaTypeNames for help.</param>
57 /// <param name="stream">File stream.</param>
58 public MessageAttachment(String mediaType, Stream stream)
60 this.mediaType = mediaType;
62 if (stream == null)
64 throw new ArgumentNullException("stream");
67 this.stream = stream;
70 /// <summary>
71 /// Initializes a new instance of the <see cref="MessageAttachment"/> class.
72 /// </summary>
73 /// <param name="fileName">Name of the file.</param>
74 /// <param name="mediaType">Type of the media.</param>
75 /// <param name="stream">The stream.</param>
76 public MessageAttachment(string fileName, string mediaType, Stream stream) : this(mediaType, stream)
78 this.fileName = fileName;
81 /// <summary>
82 /// Gets the name of the file.
83 /// </summary>
84 /// <value>The name of the file.</value>
85 public String FileName
87 get { return fileName; }
88 set { fileName = value; }
91 /// <summary>
92 /// Gets the type of the media.
93 /// </summary>
94 /// <value>The type of the media.</value>
95 public String MediaType
97 get { return mediaType; }
100 /// <summary>
101 /// Gets the stream.
102 /// </summary>
103 /// <value>The stream.</value>
104 public Stream Stream
106 get { return stream; }