Beispiel #1
0
        /// <summary>
        /// Create a new e-mail envelop based on the given
        /// e-mail builder data.
        /// </summary>
        /// <param name="MailBuilder">An e-mail builder.</param>
        public EMailEnvelop(AbstractEMailBuilder MailBuilder)
        {
            MailBuilder.EncodeBodyparts();

            // ToDo: Deep cloning!
            this._MailFrom = new EMailAddressList(MailBuilder.From);
            this._RcptTo   = new EMailAddressList(MailBuilder.To);
            this._Mail     = new EMail(MailBuilder);
        }
Beispiel #2
0
 /// <summary>
 /// Create a new e-mail envelop based on the given sender
 /// and receiver addresses and the e-mail builder data.
 /// </summary>
 /// <param name="MailFrom">The sender(s) of the e-mail.</param>
 /// <param name="RcptTo">The receiver(s) of the e-mail.</param>
 /// <param name="MailBuilder">An e-mail builder.</param>
 /// <param name="RemoteSocket">The remote socket of the incoming SMTP connection.</param>
 public EMailEnvelop(EMailAddressList MailFrom,
                     EMailAddressList RcptTo,
                     AbstractEMailBuilder MailBuilder,
                     IPSocket RemoteSocket = null)
 {
     this._RemoteSocket = RemoteSocket;
     this._MailFrom     = MailFrom;
     this._RcptTo       = RcptTo;
     this._Mail         = new EMail(MailBuilder);
 }
Beispiel #3
0
        /// <summary>
        /// Create a new e-mail based on the given e-mail builder.
        /// </summary>
        /// <param name="MailBuilder">An e-mail builder.</param>
        public EMail(AbstractEMailBuilder MailBuilder)

            : this(MailBuilder.
                   EncodeBodyparts().
                   // Copy only everything which is not related to the e-mail body!
                   MailHeaders.Where(header => !header.Key.ToLower().StartsWith("content")).
                   Concat(MailBuilder.Body.MailHeaders))

        {
            //ToDo: Do a real deep-copy here!
            Body = MailBuilder.Body;

            //ToDo: Work-aroung for PGP/GPG!
            this.From = MailBuilder.From;
            this.To   = MailBuilder.To;
            this.Cc   = MailBuilder.Cc;
        }
Beispiel #4
0
        /// <summary>
        /// Create a new e-mail bodypart.
        /// </summary>
        public EMailBodypart(AbstractEMailBuilder EMailBuilder,
                             IEnumerable <String> Content = null,
                             IEnumerable <EMailBodypart> NestedBodyparts = null)

        {
            // Only copy all e-mail headers starting with "content"...
            base._MailHeaders.AddRange(EMailBuilder.MailHeaders.Where(header => header.Key.ToLower().StartsWith("content")));

            this._MailBody.AddRange(Content);
            this._NestedBodyparts = NestedBodyparts != null
                                                ? new List <EMailBodypart>(NestedBodyparts)
                                                : (IEnumerable <EMailBodypart>) new EMailBodypart[0];

            if (_NestedBodyparts.Count() > 0)
            {
                this.ContentType.GenerateMIMEBoundary();
            }
        }
Beispiel #5
0
        /// <summary>
        /// Adds the given file as an attachment to the given e-mail.
        /// </summary>
        /// <typeparam name="T">The type of the e-mail builder.</typeparam>
        /// <param name="MailBuilder">An e-mail builder.</param>
        /// <param name="FileInfo">The file to add.</param>
        /// <param name="ContentType">The content type of the file to add.</param>
        /// <param name="ContentLanguage">The content language of the file to add.</param>
        public static T AddAttachment <T>(this AbstractEMailBuilder MailBuilder,
                                          FileInfo FileInfo,
                                          MailContentTypes ContentType = MailContentTypes.text_plain,
                                          String ContentLanguage       = null)

            where T : AbstractEMailBuilder

        {
            #region Initial checks

            if (MailBuilder == null)
            {
                throw new ArgumentNullException("The given e-mail builder must not be null!");
            }

            if (FileInfo == null)
            {
                throw new ArgumentNullException("The given file name must not be null or empty!");
            }

            if (!FileInfo.Exists)
            {
                throw new ArgumentNullException("The given file does not exist!");
            }

            #endregion

            return(MailBuilder.AddAttachment <T>(

                       new EMailBodypart(ContentTypeBuilder:       AMail => new MailContentType(AMail, ContentType)
            {
                CharSet = "utf-8"
            },
                                         ContentTransferEncoding:  "base64",
                                         ContentLanguage:          ContentLanguage,
                                         Content:                  new String[] { Convert.ToBase64String(File.ReadAllBytes(FileInfo.FullName)) }).

                       SetEMailHeader("Content-Disposition", ContentDispositions.attachment.ToString() + "; filename=\"" + FileInfo.Name + "\"")));
        }