Sample code for 30+ languages & platforms
Visual FoxPro

Add Duplicate Header Fields to an Email

See more Email Object Examples

Demonstrates the Chilkat Email.AddHeaderField2 method. It works like AddHeaderField, except that if the header field already exists it is not replaced — a duplicate header is added instead. Use it for headers that may legally occur more than once, such as Received. This example adds two headers with the same name and prints the header showing both.

Background: The email standards allow certain header fields to repeat. The classic case is Received: each mail server that handles a message prepends its own Received line, so a delivered email typically has several, forming a trace of the path it took. Single-valued fields like Subject should be replaced (use AddHeaderField), whereas repeatable fields need AddHeaderField2 so earlier occurrences are preserved rather than overwritten.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL loEmail

*  Demonstrates the AddHeaderField2 method.  It is the same as AddHeaderField, except that
*  if the header field already exists, it is NOT replaced -- a duplicate header is added.
*  Use this for headers that may legally occur more than once, such as "Received".

loEmail = CreateObject('Chilkat.Email')
loEmail.Subject = "Duplicate header example"
loEmail.From = "alice@example.com"

*  Add two header fields with the same name; both are retained.
loEmail.AddHeaderField2("X-Trace","hop-1")
loEmail.AddHeaderField2("X-Trace","hop-2")

*  Both X-Trace fields are present in the header.
? loEmail.Header

RELEASE loEmail