PowerTCP Mail for .NET
Header Property
See Also  Send comments on this topic.
Dart.PowerTCP.Mail Namespace > MessageStream Class : Header Property




Gets or sets a MailHeader collection representing the mail header lines of the message. Inherits from ArrayList.

Syntax

Visual Basic (Declaration) 
Public Property Header As MailHeader
Visual Basic (Usage)Copy Code
Dim instance As MessageStream
Dim value As MailHeader
 
instance.Header = value
 
value = instance.Header
C# 
public MailHeader Header {get; set;}
Managed Extensions for C++ 
public: __property MailHeader* get_Header();
public: __property void set_Header( 
   MailHeader* value
);
C++/CLI 
public:
property MailHeader^ Header {
   MailHeader^ get();
   void set (    MailHeader^ value);
}

Property Value

A MailHeader collection representing the mail header lines.

Example

The following example demonstrates the many ways a MIME message can be created.
Visual BasicCopy Code
' Be sure to import the namespace by putting "Imports Dart.PowerTCP.Mail"
' at the top of your class. In addition, import System.IO, as a FileStream will be used.

' Create a MessageStream object
Dim msg As New MessageStream()

' Add a normal recipient
msg.To.Add(New MailAddress("you@test.com"))

' Specify the sender
msg.From = New MailAddress("me@test.com")

' Specify the subject
msg.Subject = "Test"

' Add a MIME attachment
msg.Parts.Attachments.Add(New MimeAttachmentStream("C:\files\graph.bmp"))

' Add some MIME text (Setting MessageStream.Text also does this).
msg.Parts.Simple.Add(New MessagePartStream("More text here"))

' Create a complex MIME part from a stored message.
msg.Parts.Complex.Add(New MessageStream(New FileStream("C:\\message.eml", FileMode.Open)))

' Create a custom MIME boundary to use. (the component will 
' create a default MIME boundary to use if this isn't specified)
msg.MimeBoundary = "----MyBoundary-----"

' Override automatic date setting
msg.Date = ""

' Add a header line.
msg.Header.Add(HeaderLabelType.Organization, "My Organization")

' Now add a custom header line.
msg.Header.Add("X-My-Field: My Value")

' Specify the server
Smtp1.Server = "mail.test.com"

' Send the message
Smtp1.Send(msg)
C#Copy Code
// Be sure to import the namespace by putting "using Dart.PowerTCP.Mail;"
// at the top of your class. In addition, import System.IO, as a FileStream will be used.\

// Create a MessageStream object
MessageStream msg = new MessageStream();

// Add a normal recipient
msg.To.Add(new MailAddress("you@test.com"));

// Specify the sender
msg.From = new MailAddress("me@test.com");

// Specify the subject
msg.Subject = "Test";

// Add a MIME attachment
msg.Parts.Attachments.Add(new MimeAttachmentStream("C:\\files\\graph.bmp"));

// Add some MIME text (MessageStream.Text also does this).
msg.Parts.Simple.Add(new MessagePartStream("More text here"));
		
// Create a complex MIME part from a stored message.
msg.Parts.Complex.Add(new MessageStream(new FileStream("C:\\message.eml", FileMode.Open)));

// Create a custom MIME boundary to use. (the component will 
// create a default MIME boundary to use if this isn't specified)
msg.MimeBoundary = "----MyBoundary-----";

// Override automatic date setting
msg.Date = "";

// Add a header line.
msg.Header.Add(HeaderLabelType.Organization, "My Organization");

// Now add a custom header line.
msg.Header.Add("X-My-Field: My Value");

// Specify the server
smtp1.Server = "mail.test.com";

// Send the message
smtp1.Send(msg);

Remarks

When creating a message, mail header lines can be added two ways:

  • They can be explicitly added by using MessageStream.Header.Add.
  • They can be added by using a high-level property, such as MessageStream.Subject.

    In the latter case, setting MessageStream.Subject will actually add a item to the MailHeader collection and, as a result, this collection will always reflect the current header of the message. The reverse is also true. For example, if MessageStream.Header.Add(HeaderLabelType.Subject, "Hello") was used, the MessageStream.Subject property would return "Hello".

    The "Content-Type" header line can also be altered by accessing the MailHeader collection but this is not recommended. The recommended way to alter this header line is by setting MessageStream.Type.

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.