Gets or sets the date and the time when the mail message was composed.
The date when the mail message was composed. The default value is MinValue.
In the case when an existing message gets parsed, the value of this property is taken from Date header.
Otherwise, if a new message is being sent or submitted to the pickup folder and SetDateOnSend property is true, Date value will be set to Now directly at the moment of sending.
On other hand, if SetDateOnSend property is set to false, the existing value of Date header will be used. If it's MinValue, Date header will not be added to the message.
When the message gets built without sending (for instance, when you save it into a file), Date value is not changed. Thus, if you did not set it manually, no Date header will present in the resulting message.
To set the date to the current date and time, you can use msg.Date=DateTime.Now (assuming msg is MailMessage instance).
You can also use SetDateFromString method to set Date header value from a string.
To get the date when the message was delivered to the mailbox (rather than composed), use DateReceived property.
| Exception Type | Condition |
|---|---|
| MailBeeDateParsingException | A date parsing error occurred and ThrowExceptions is true. |
This sample loads the message from .EML file and changes the date and time when the message was composed. In the modified message, it will appear that the message was composed earlier today at midnight, not at the current moment.
Then, the sample suppresses automatic setting the date and time to Now during sending, and sends the message.
[C#] using System; using MailBee; using MailBee.SmtpMail; using MailBee.Mime; class Sample { static void Main(string[] args) { // Load the message from file. MailMessage msg = new MailMessage(); msg.LoadMessage(@"C:\Docs\TestMail.eml"); // Set the date to the current date and 00-00 time. msg.Date = DateTime.Today; // Suppress automatic setting Date to the current datetime // when the message gets sent. msg.Builder.SetDateOnSend = false; // Send it. Smtp.QuickSend(msg); } }
[Visual Basic] Imports System Imports MailBee Imports MailBee.SmtpMail Imports MailBee.Mime Module Sample Sub Main(ByVal args As String()) ' Load the message from file. Dim msg As New MailMessage msg.LoadMessage("C:\Docs\TestMail.eml") ' Set the date to the current date and 00-00 time. msg.Date = DateTime.Today ' Suppress automatic setting Date to the current datetime ' when the message gets sent. msg.Builder.SetDateOnSend = False ' Send it. Smtp.QuickSend(msg) End Sub End Module
MailMessage Class | MailBee.Mime Namespace | DateReceived | SetDateFromString | SetDateOnSend