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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.