Exemplo n.º 1
0
        // end added by mb

        /// <summary>Constructor using a file path</summary>
        /// <example>
        /// <code>Attachment a = new Attachment("C:\\file.jpg");</code>
        /// </example>
        public Attachment(string filePath)
        {
            this.filePath = filePath;

            if (filePath.Length > 0)
            {
                try
                {
                    FileInfo fileInfo = new FileInfo(filePath);
                    if (fileInfo.Exists)
                    {
                        this.mimeType = getMimeType(fileInfo.Extension);
                        this.name     = fileInfo.Name;
                        this.size     = (int)fileInfo.Length;

                        string encodedTempFile = Path.GetTempFileName();
                        MailEncoder.ConvertToBase64(filePath, encodedTempFile);
                        this.encodedFilePath = encodedTempFile;
                    }
                }
                catch (ArgumentNullException)
                {
                    throw new SmtpException("Attachment file does not exist or path is incorrect.");
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>Constructor using a provided Stream</summary>
        /// <example>
        /// <code>Attachment a = new Attachment(new FileStrema(@"C:\file.jpg", FileMode.Open, FileAccess.Read), "file.jpg");</code>
        /// </example>
        public Attachment(Stream stream, string fileName)
        {
            try
            {
                this.mimeType = "unknown/application";
                this.name     = fileName;
                this.size     = (int)stream.Length;

                string encodedTempFile = Path.GetTempFileName();
                MailEncoder.ConvertToBase64(stream, encodedTempFile);
                this.encodedFilePath = encodedTempFile;
            }
            catch (ArgumentNullException)
            {
                throw new SmtpException("Attachment file does not exist or path is incorrect.");
            }
        }