1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
20 public enum AttachmentEncoding
27 /// Represents a file attachment
29 public class MessageAttachment
31 private String fileName
;
32 private readonly String mediaType
;
33 private readonly Stream stream
;
36 /// Creates a new attachment
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
;
54 /// Creates a new attachment
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
;
64 throw new ArgumentNullException("stream");
71 /// Initializes a new instance of the <see cref="MessageAttachment"/> class.
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
;
82 /// Gets the name of the file.
84 /// <value>The name of the file.</value>
85 public String FileName
87 get { return fileName; }
88 set { fileName = value; }
92 /// Gets the type of the media.
94 /// <value>The type of the media.</value>
95 public String MediaType
97 get { return mediaType; }
103 /// <value>The stream.</value>
106 get { return stream; }