ASP 101 - Active Server Pages 101 - Web03
The Place ASP Developers Go!

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Quick Tips

Setting an Outlook Flag on an Email Message

If you're anything like me, at times you probably get a little overwhelmed by the amount of email you need to process. To help you manage your mail, Microsoft Outlook offers you the ability to flag messages with different status codes... the most common one being "Follow up". But why should we have to set this flag ourselves?

For example, if you receive things like sales leads or error notifications via email, wouldn't it make sense if they came to you already flagged for follow up? After all, if we didn't need to follow up on them then why would we have written script to send ourselves the email in the first place? Then once you handle the message you simply clear the flag or flag the message as complete. This way you can easily see which messages you've handled and which ones you still need to address. Luckily, it's not difficult to set these status flags before you send an email message and make this a reality.

Outlook manages these flags via the email message headers. Specifically one called "X-Message-Flag". By simply assigning some text to this header, Outlook will display the message as flagged and will display the text in the little banner that appears when you view a flagged message. In testing, I was able to set the text to anything I wanted, but it's probably best if you stick to Outlook's standard flag messages.

In ASP.NET 2.0 the syntax to set this flag looks something like this:

myMessage.Headers.Add("X-Message-Flag", "Follow up")

As cool as this is, Outlook flagging magic doesn't stop there. If you want, you can even specify a date and time by which the recipient should follow up:

myMessage.Headers.Add("Reply-By", _
    Format(dtReplyBy, "ddd, dd MMM yyyy HH:mm:ss zz") & "00")

Now if we could only set a flag to make sure they actually follow up on the message!

Here's an ASP.NET 2.0 script illustrating the use of the headers mentioned above:

<%@ Page Language="VB" %>
<%@ Import Namespace="System.Net.Mail" %>
<script runat="server">
  Protected Sub btnSendEmail_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs)

    Dim strFrom, strTo, strSubject, strBody As String
    Dim dtReplyBy As DateTime
    Dim myMessage As MailMessage
    Dim mySmtpClient As SmtpClient

    strFrom    = "FROM ADDRESS GOES HERE"
    strTo      = "TO ADDRESS GOES HERE"
    strSubject = "Outlook Email Flag Sample"
    strBody    = "This script shows how to add an " _
      & "Outlook flag header to an email message."

    dtReplyBy = DateAdd(DateInterval.Day, 1, Now())

    myMessage = New MailMessage(strFrom, strTo, strSubject, strBody)
    myMessage.Headers.Add("X-Message-Flag", "Follow up")
    myMessage.Headers.Add("Reply-By", _
      Format(dtReplyBy, "ddd, dd MMM yyyy HH:mm:ss zz") & "00")

    mySmtpClient = New SmtpClient("localhost")
  End Sub
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="" >
  <title>Outlook Email Flag Sample Page</title>
  <form id="myForm" runat="server">
    <asp:Button ID="btnSendEmail" runat="server"
      Text="Send Email" OnClick="btnSendEmail_Click"

Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to:

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers