Setting email expiry date

I came accross a task to set expiry date for outgoing emails. Although there is a Mail header to set the expiry date for an email, but it is one of the optional ones, so not many clients implement that.
lists the header which is called “Expiry-Date” which has now been replaced in the new RFC by “Expires” , so setting this property in the System.Net.Mail MailMessage class I was able to expire the email as required.

Here is the little code

MailAddress from = new MailAddress(strEmailFrom, strEmailFrom);
MailAddress to = new MailAddress(strEmailto, strEmailto);
MailMessage message = new MailMessage(from, to);
message.Subject = strEmailSubject;
message.Body = strEmailBody;
message.IsBodyHtml = true;

DateTime dt = DateTime.Now;
dt = dt.AddDays(1);
//set the expires header for the email
//message.Headers.Add(“Expires”, String.Format(“{0:F}”, dt)); // this is according to the new RFC
message.Headers.Add(“Expiry-Date”, String.Format(“{0:F}”, dt)); // old RFC format
// Add a carbon copy recipient.
MailAddress copy = new MailAddress(strEmailFrom);
SmtpClient client = new SmtpClient(ConfigurationSettings.AppSettings[“MailServer”].ToString());
// Include credentials if the server requires them.
client.Credentials = CredentialCache.DefaultNetworkCredentials;

1 thought on “Setting email expiry date

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s