Beispiel #1
0
		private bool _HeadersOnly; // set to true if only headers have been fetched. 

		public MailMessage() {
			RawFlags = new string[0];
			To = new Collection<MailAddress>();
			Cc = new Collection<MailAddress>();
			Bcc = new Collection<MailAddress>();
			ReplyTo = new Collection<MailAddress>();
			Attachments = new Collection<Attachment>();
			AlternateViews = new AlternateViewCollection();
		}
 /// <summary>Initializes an empty instance of the <see cref="T:System.Net.Mail.MailMessage" /> class.</summary>
 public MailMessage()
 {
     this.to             = new MailAddressCollection();
     this.alternateViews = new AlternateViewCollection();
     this.attachments    = new AttachmentCollection();
     this.bcc            = new MailAddressCollection();
     this.cc             = new MailAddressCollection();
     this.replyTo        = new MailAddressCollection();
     this.headers        = new System.Collections.Specialized.NameValueCollection();
     this.headers.Add("MIME-Version", "1.0");
 }
Beispiel #3
0
 /// <summary>Initializes an empty instance of the <see cref="T:System.Net.Mail.MailMessage" /> class.</summary>
 public MailMessage()
 {
     to             = new MailAddressCollection();
     alternateViews = new AlternateViewCollection();
     attachments    = new AttachmentCollection();
     bcc            = new MailAddressCollection();
     cc             = new MailAddressCollection();
     replyTo        = new MailAddressCollection();
     headers        = new NameValueCollection();
     headers.Add("MIME-Version", "1.0");
 }
		public MailMessage () {
			this.to = new MailAddressCollection ();

			alternateViews = new AlternateViewCollection ();
			attachments = new AttachmentCollection ();
			bcc = new MailAddressCollection ();
			cc = new MailAddressCollection ();
			replyTo = new MailAddressCollection ();
			headers = new NameValueCollection ();

			headers.Add ("MIME-Version", "1.0");
		}
		public void GetReady ()
		{
			avc = new  MailMessage ("*****@*****.**", "*****@*****.**").AlternateViews;
			av = AlternateView.CreateAlternateViewFromString ("test", new ContentType ("text/plain"));
		}
Beispiel #6
0
        private void SendBodyWithAlternateViews(MailMessage message, string boundary, bool attachmentExists)
        {
            AlternateViewCollection alternateViews = message.AlternateViews;

            string inner_boundary = GenerateBoundary();

            ContentType messageContentType = new ContentType();

            messageContentType.Boundary  = inner_boundary;
            messageContentType.MediaType = "multipart/alternative";

            if (!attachmentExists)
            {
                SendHeader(HeaderName.ContentType, messageContentType.ToString());
                SendData(String.Empty);
            }

            // body section
            AlternateView body = null;

            if (message.Body != null)
            {
                body = AlternateView.CreateAlternateViewFromString(message.Body, message.BodyEncoding, message.IsBodyHtml ? "text/html" : "text/plain");
                alternateViews.Insert(0, body);
                StartSection(boundary, messageContentType);
            }

            try {
                // alternate view sections
                foreach (AlternateView av in alternateViews)
                {
                    string      alt_boundary = null;
                    ContentType contentType;
                    if (av.LinkedResources.Count > 0)
                    {
                        alt_boundary                    = GenerateBoundary();
                        contentType                     = new ContentType("multipart/related");
                        contentType.Boundary            = alt_boundary;
                        contentType.Parameters ["type"] = "application/octet-stream";
                        StartSection(inner_boundary, contentType);
                    }
                    else
                    {
                        contentType = new ContentType(av.ContentType.ToString());
                        StartSection(inner_boundary, contentType, av.TransferEncoding);
                    }

                    switch (av.TransferEncoding)
                    {
                    case TransferEncoding.Base64:
                        byte [] content = new byte [av.ContentStream.Length];
                        av.ContentStream.Read(content, 0, content.Length);
#if TARGET_JVM
                        SendData(Convert.ToBase64String(content));
#else
                        SendData(Convert.ToBase64String(content, Base64FormattingOptions.InsertLineBreaks));
#endif
                        break;

                    case TransferEncoding.QuotedPrintable:
                        byte [] bytes = new byte [av.ContentStream.Length];
                        av.ContentStream.Read(bytes, 0, bytes.Length);
                        SendData(ToQuotedPrintable(bytes));
                        break;

                    case TransferEncoding.SevenBit:
                    case TransferEncoding.Unknown:
                        content = new byte [av.ContentStream.Length];
                        SendData(Encoding.ASCII.GetString(content));
                        break;
                    }

                    if (av.LinkedResources.Count > 0)
                    {
                        SendLinkedResources(message, av.LinkedResources, alt_boundary);
                        EndSection(alt_boundary);
                    }

                    if (!attachmentExists)
                    {
                        SendData(string.Empty);
                    }
                }
            } finally {
                if (body != null)
                {
                    alternateViews.Remove(body);
                }
            }
            EndSection(inner_boundary);
        }