Beispiel #1
0
        /// <summary>
        /// Encode the email body as it will appear in the email
        /// </summary>
        /// <returns>the encoded body</returns>
        internal String ToDataStringBody()
        {
            bool mixedistop=false;
            bool relatedistop=false;
            bool alternativeistop=false;

            if (HasBodyTextOnly())
            {
                return FormatBodyText(_bodytext);
            }

            MimeBoundary relatedcontentmimeboundary=null;
            MimeBoundary mixedcontentmimeboundary=null;
            MimeBoundary altertnativecontentmimeboundary=null;

            #region Determine which uses the top-level boundary
            if (HasMixedContent())
            {
                mixedistop=true;
                mixedcontentmimeboundary=_mimeboundary;
                relatedcontentmimeboundary=new MimeBoundary();
                altertnativecontentmimeboundary=new MimeBoundary();
            }
            else if (HasRelatedContent())
            {
                relatedistop=true;
                relatedcontentmimeboundary=_mimeboundary;
                altertnativecontentmimeboundary=new MimeBoundary();
            }
            else
            {
                alternativeistop=true;
                altertnativecontentmimeboundary=_mimeboundary;
            }
            #endregion

            MimeContainer alternativemimecontainer=new MimeContainer(altertnativecontentmimeboundary, "multipart/alternative", alternativeistop);
            MimeContainer topcontainer=alternativemimecontainer;

            #region Text & HTML Parts
            if (_textpart!=null)
            {
                alternativemimecontainer.AddAttachment(_textpart);
            }

            if (_htmlpart!=null)
            {
                alternativemimecontainer.AddAttachment(_htmlpart);
            }
            #endregion

            #region Related Content
            if (HasRelatedContent())
            {
                //topcontainer=new MimeContainer(relatedcontentmimeboundary, "multipart/related", relatedistop);
                topcontainer=new MimeContainer(relatedcontentmimeboundary, "multipart/related;\r\n       type=\"multipart/alternative\"", relatedistop);
                topcontainer.AddMimeContainer(alternativemimecontainer);
                foreach (FileAttachment attachment in _relatedfileattachments)
                {
                    topcontainer.AddAttachment(attachment);
                }
            }
            #endregion

            #region Mixed Content
            if (HasMixedContent())
            {

                MimeContainer oldtopcontainer=topcontainer;
                topcontainer=new MimeContainer(mixedcontentmimeboundary, "multipart/mixed", mixedistop);
                topcontainer.AddMimeContainer(oldtopcontainer);

                foreach (FileAttachment attachment in _mixedfileattachments)
                {
                    topcontainer.AddAttachment(attachment);
                }

            }
            #endregion

            if (_bodytext==null)
            {
                return topcontainer.ToDataString();
            }
            else
            {
                return FormatBodyText(_bodytext)+".\r\n\r\n"
                    +topcontainer.ToDataString();
            }
        }
Beispiel #2
0
 public void AddMimeContainer(MimeContainer mimecontainer)
 {
     _mimecontainers.Add(mimecontainer);
 }
Beispiel #3
0
        /// <summary>
        /// Encode the email body as it will appear in the email
        /// </summary>
        /// <returns>the encoded body</returns>
        internal String ToDataStringBody()
        {
            bool mixedistop       = false;
            bool relatedistop     = false;
            bool alternativeistop = false;

            if (HasBodyTextOnly())
            {
                return(FormatBodyText(_bodytext));
            }

            MimeBoundary relatedcontentmimeboundary      = null;
            MimeBoundary mixedcontentmimeboundary        = null;
            MimeBoundary altertnativecontentmimeboundary = null;

            #region Determine which uses the top-level boundary
            if (HasMixedContent())
            {
                mixedistop = true;
                mixedcontentmimeboundary        = _mimeboundary;
                relatedcontentmimeboundary      = new MimeBoundary();
                altertnativecontentmimeboundary = new MimeBoundary();
            }
            else if (HasRelatedContent())
            {
                relatedistop = true;
                relatedcontentmimeboundary      = _mimeboundary;
                altertnativecontentmimeboundary = new MimeBoundary();
            }
            else
            {
                alternativeistop = true;
                altertnativecontentmimeboundary = _mimeboundary;
            }
            #endregion

            MimeContainer alternativemimecontainer = new MimeContainer(altertnativecontentmimeboundary, "multipart/alternative", alternativeistop);
            MimeContainer topcontainer             = alternativemimecontainer;

            #region Text & HTML Parts
            if (_textpart != null)
            {
                alternativemimecontainer.AddAttachment(_textpart);
            }

            if (_htmlpart != null)
            {
                alternativemimecontainer.AddAttachment(_htmlpart);
            }
            #endregion

            #region Related Content
            if (HasRelatedContent())
            {
                //topcontainer=new MimeContainer(relatedcontentmimeboundary, "multipart/related", relatedistop);
                topcontainer = new MimeContainer(relatedcontentmimeboundary, "multipart/related;\r\n       type=\"multipart/alternative\"", relatedistop);
                topcontainer.AddMimeContainer(alternativemimecontainer);
                foreach (FileAttachment attachment in _relatedfileattachments)
                {
                    topcontainer.AddAttachment(attachment);
                }
            }
            #endregion

            #region Mixed Content
            if (HasMixedContent())
            {
                MimeContainer oldtopcontainer = topcontainer;
                topcontainer = new MimeContainer(mixedcontentmimeboundary, "multipart/mixed", mixedistop);
                topcontainer.AddMimeContainer(oldtopcontainer);

                foreach (FileAttachment attachment in _mixedfileattachments)
                {
                    topcontainer.AddAttachment(attachment);
                }
            }
            #endregion

            if (_bodytext == null)
            {
                return(topcontainer.ToDataString());
            }
            else
            {
                return(FormatBodyText(_bodytext) + ".\r\n\r\n"
                       + topcontainer.ToDataString());
            }
        }
Beispiel #4
0
 public void AddMimeContainer(MimeContainer mimecontainer)
 {
     _mimecontainers.Add(mimecontainer);
 }