Click here to Skip to main content
Licence 
First Posted 18 Aug 2003
Views 41,310
Bookmarked 15 times

Sending E-mails from ASP.NET with expiry dates

By | 18 Aug 2003 | Article
How to apply an expiry date to an E-mail so that it will work correctly with the expires-after field in Microsoft Exchange (i.e. Outlook).

Introduction

Have you ever wanted to set an expiry time on an E-mail you send using the System.Web.Mail class library? The solution is pretty simple but I puzzled for a while over this and couldn't find any samples, and so I thought it might be helpful to submit some code.

The Code

Dim sTime As String = _
   Now().AddDays(1).ToString("dd MMM yyyy") & " " & _
   Now().ToShortTimeString & " +0100"
Dim objMsg As New 
MailMessage
objMsg.BodyFormat = MailFormat.Html
objMsg.To = "you@home.com"
objMsg.From = "me@home.com"
objMsg.Subject = "Expiry Test"
objMsg.Body = "<p>test</p>"
objMsg.Headers.Add("expiry-date", sTime)
SmtpMail.SmtpServer = "myServer"
SmtpMail.Send(objMsg)

Explanation

Note the special format required for the Date/Time - the "+0100" at the end indicates your time zone, in this case one hour ahead of GMT. In this case of course I have set the expiry date as one day from Now()

This requires a reference to System.Web.Mail which suggests Web Forms but can be used in any .NET application.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

rohancragg

Web Developer

United Kingdom United Kingdom

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionWinform? PinmemberMuhammad Waqas Butt23:58 25 Aug '05  
AnswerRe: Winform? Pinmemberrohancragg3:51 26 Aug '05  
GeneralRe: Winform? PinmemberMuhammad Waqas Butt4:41 27 Aug '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 19 Aug 2003
Article Copyright 2003 by rohancragg
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid