I am creating a website where we make moderate use of email templates. Like in HTML templates to which we transfer tokens, for example {UserName}, {Email}, {NameFirst}, etc.
I struggle with where to store them as much as possible. First, I will show the approach that I took, and I would be very glad to hear some kind of expert perspective, as alternative approaches.
I created HTML templates in a folder called / Templates /.
I call a static method at my service level that takes the following arguments:
- Username
- User ID
- Email
- TemplatePath ("~ / Templates")
- Email subject
Within the service level, I have my static SendUserEmail () method, which uses the Template class β which takes a path, loads it as a string, and has the AddToken () method.
In my static SendUserEmail (), I build a list of tokens from the method signature and send an email.
This leads to a rather long method call in my actual use, especially since I call "TemplatePath" and "Email Subject" from web.config. I could create a utility with a shorter method call than ConfigurationManager.AppSettings, but my concern is that I usually donβt see method signatures for so long, and it seems to me that I am doing something wrong.
This method is great for emails that I have now, which in most cases use the first 3 tokens. However, in the future I will have more tokens to go through, and I'm just wondering which approach to take.
Create email specific methods to send? i.e. SendNewUserRegistration (), SendMarketingMaterial (), and each has a different signature for the parameters?
I am using ASP.NET membership, which probably contains an extension of all the fields that I will ever need. There are three main objects: aspnet_User, aspnet_Mebership, and aspnet_profile. If all this were contained in one object, I would simply pass it. Are there any performance issues with the transfer in all 3 to get all the fields I need? Is it against the fact that you are simply passing aspnet_User.UserID, aspnet_User.Email, etc.?
I could see that there are entries with tokens in the dictionary, but I'm just wondering if there is too much to ask the calling page?
Is there a way to insert them into the configuration file from its own name Templates.config, in which there are tags, for example -
<Templates> <EmailTemplate Name="New User Registration"> <Tokens> <UserName> <UserID> <Email> </Tokens> <Message Subject="Hi welcome..."> Hi {UserName}... </Message> </EmailTemplate> </Templates>
I assume that the main reason I am asking for is that it is difficult for me to determine where the responsibility should be, how much to determine which template to use, and how to pass parameters. Is this normal if the calling page is to build the TokenName dictionary, TokenValue? Or should the method take each as a specific parameter? This looks out of place in web.config because I have 2 entries for and, and it seems to me that it should look more nested.
Thanks. Any methods or suggestions of an objective approach that I can use to ask if my approach is appropriate.