When i try to send email with past dates using PostedDate
the emails are sended with current date time and not with the date specified in the PostedDate
field. It is possible to send the emails with past dates and is there any other ways are there? Since I want large data in the past to test backup functionality(it is really needed).
static void CreateEmail(NotesDatabase userDatabase)
{
if (!userDatabase.IsOpen)
{
userDatabase.Open();
}
NotesDocument LNDocument = userDatabase.CreateDocument();
string[] recipients =
{"contact1/test@test","contact2/test@test"};
string emailSender = "sender@test.com";
LNDocument.ReplaceItemValue("Form", "Memo");
LNDocument.ReplaceItemValue("From", emailSender);
LNDocument.ReplaceItemValue("SMTPOriginator", emailSender);
LNDocument.ReplaceItemValue("Sender", emailSender);
LNDocument.ReplaceItemValue("INetFrom", emailSender);
LNDocument.ReplaceItemValue("Principal", emailSender);
LNDocument.ReplaceItemValue("SendTo", recipients); //To field
LNDocument.ReplaceItemValue("Subject", "Test Email"); //message subject
LNDocument.ReplaceItemValue("Body", "Test Email Lotus Notes"); //set body text
System.DateTime StartDate = new DateTime(2019, 12, 23, 7, 0, 0);
LNDocument.ReplaceItemValue("PostedDate", StartDate);
LNDocument.SaveMessageOnSend = true; //save message after it's sent
LNDocument.Send(false,recipients ); //send
}
The answer is simple: Don't send them. The "PostedDate" item is an item that is automatically set by the router. You are not able to fake this date easily ("Hey, but I sent you the mail yesterday, look at the PostedDate..." ).
BUT: Instead of sending the mails you could simply directly create them in the recipients mailbox and set all the items as if it in deed had been sent.
The only additional thing the router does, is to put the mail in the inbox of the recipient, so you need to do that as well:
If you really want to keep the "sent" document in the senders database as well, then so something like this:
Instead of
LNDocument.SaveMessageOnSend = true; //save message after it's sent
LNDocument.Send(false,recipients ); //send
Write
NotesDatabase recipientDatabase
NotesDocument recipientDocument
LNDocument.Save(true,true,true); //save
// get the database of recipient here, lookup in ($User)- view
// in names.nsf on server and get MailPath, write a function for this...
recipientDatabase = ....
recipientDocument = LNDocument.CopyToDatabase(recipientDatabase)
recipientDocument.PutInFolder( "($Inbox)" )