- 
                Notifications
    You must be signed in to change notification settings 
- Fork 32
Message Storage
        Norbert Bietsch edited this page Mar 7, 2018 
        ·
        1 revision
      
    The FileMessageStore let's you manage mail messages stored in the file system. You can add all the locations and the search pattern for message files.
var fms = new FileMessageStore(new[] { "path-to-message-files" }, new[] { "Msg*.xml" }, Encoding.UTF8);
fms.Serialize("my-file-message-store.config", Encoding.UTF8);Later you can load the FileMessageStore:
var fms = FileMessageStore.Deserialize("my-file-message-store.config", Encoding.UTF8);// prepare the sender
var mms = new MailMergeSender()
{
    Config = Settings.Deserialize("path-to-settings-file", Encoding.UTF8).SenderConfig
};
// send each message loaded from the FileMessageStore
foreach (var info in fms.ScanForMessages())
{
    // messageInfos come from fast xml scan in MessageInfoBase, 
    // Info of the Messsage comes from YAXLib deserialization
    var mmm = info.LoadMessage();
                
    // sample for generating variables - to be implmented
    var variables = LoadDataFromSqlServer(info.Data);
    await mms.SendAsync(mmm, variables);
}These few lines of code are the essence that you need to send a bunch of mail messages.
You can implement your own message store by implementing the IMessageStore interface. This could become e.g. a "MySqlMessageStore". For this task Dapper, a Micro-ORM supporting SQL Server, MySQL, Sqlite, SqlCE, Firebird etc. could be interesting.