Setting Expiry of a CDO Message (SMTP)?

I'm sending emails within my company to users, using CDO, Roughly like below.
I'd like the emails to self expire. Is this possible?
I know that you can do this by sending the emails through Outlook, but that isn't possible in my situation. I need to use the method below.


Private Sub Form_Load()
    Dim test As New CDO.Message
    test.To = ""
    test.From = ""
    test.Subject = "Test Message"
    test.AddRelatedBodyPart "U:\Inetpub\wwwroot\~resources\tech-newsletter-head.jpg", "tech-newsletter-head.jpg", cdoRefTypeId
    test.AddRelatedBodyPart "U:\Inetpub\wwwroot\~resources\regions.jpg", "regions.jpg", cdoRefTypeId
    test.Configuration.Fields.Item("") = 2
    'Name or IP of remote SMTP server
    test.Configuration.Fields.Item("") = "my.mail.server"
    'Server port
    test.Configuration.Fields.Item("") = 25
    'Read HTML file for message body
    Open "u:\inetpub\wwwroot\temp3.htm" For Input As #1
    While Not EOF(1)
        Line Input #1, strHTMLT
        strHTML = strHTML & strHTMLT
    Close #1
    test.HTMLBody = strHTML
    Set test = Nothing
End Sub
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hello jwinney,

you could look at this article
'This message will expire at 6:00 PM on October 23, 1998
test.Configuration.Fields.Item(CdoPR_EXPIRY_TIME) = "1998/10/23 18:00:00"

hope this helps a bit
jwinneyAuthor Commented:

I've tried that. This article refers to using Outlook itself by creating a MAPI session, not SMTP


Expiry is a standard header, so just add it to the Message object:

    test.To = ""
    test.From = ""
    test.Subject = "Test Message"
    test.Fields.Item("urn:schemas:mailheader:expiry") = "Sat, 26 Apr 2006 00:00:00 -0800"

A list of headers can be found at:

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

jwinneyAuthor Commented:
Hi wnross,

Thanks, I tried that after I'd posted this question. It didn't appear to work for me. Have you tred it? It seems to be the correct way of doing it. Wondering if my SMTP server is doing something....


Possibly, you can also use the technique to place a raw header, which in this case is called Expiry-Date

 test.Fields.Item("urn:schemas:mailheader:Expiry-Date") = "Sat, 26 Apr 2006 00:00:00 -0800"

note that

 test.Configuration.Fields.Item("urn:schemas:mailheader:Expiry-Date") = "Sat, 26 Apr 2006 00:00:00 -0800"

Won't work, since that Field object is simply used to configure transportation.

Hmm, I forgot to add the second Update method, you need to use Update() on both the configuration
Field object AND the message headers Field object


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you put expiry into the configuration object or forgot to use Update, your attempt would have been discarded
jwinneyAuthor Commented:
Excellent !!

This worked:

    test.Fields.Item("urn:schemas:mailheader:Expiry-Date") = "Wed, 26 Apr 2006 15:40:00 +0100"


No problem, glad to help

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.