Saturday, April 24, 2010

Tracking messages using the message-id headeer

I am looking for ways to track email messages using some sort of heading which should be reported in each smtp-log entry. Below is a possible method I plan on experimenting with.
// The Message-ID email header field is treated somewhat specially by the
// Chilkat email component.
// Many SMTP servers will consider emails as duplicates if the Message-ID is identical,
// even if the other parts (subject, body, etc.) are different.  These SMTP servers
// may silently drop duplicates.
// The Chilkat mailman's SendEmail method automatically replaces the Message-ID header
// field in the outgoing email with a unique value.  This behavior can be turned off
// by setting the MailMan.AutoGenMessageId property = false.
// Your program may set a custom Message-ID by calling the Email.AddHeaderField method.

private void custom_message_id()
{
    // Create an instance of the mailman for the purpose of unlocking.
    Chilkat.MailMan mailman = new Chilkat.MailMan();
    mailman.UnlockComponent("Anything for 30-day trial");

    // Turn off the auto-generate message-id feature.
    mailman.AutoGenMessageId = false;

    // Create a new email object...
    Chilkat.Email email = new Chilkat.Email();
    email.Subject = "This is a test";
    email.Body = "This is the mail body";
    email.AddTo("Chilkat Support", "support@chilkatsoft.com");
    email.From = "Chilkat Sales ";

    // Set our own Message-ID
    // The AddHeaderField method will replace a header field if it already exists.
    email.AddHeaderField("Message-ID", "4387ty6wer7g8745e8rtg");

    // Send the email.
    mailman.SmtpHost = "smtp.comcast.net";

    bool success = mailman.SendEmail(email);
    if (!success)
    {
        MessageBox.Show(mailman.LastErrorText);
    }
    else
    {
        MessageBox.Show("Mail Sent!");
    }

}

Kudos to http://www.example-code.com/csharp/message-id-header.asp

No comments: