這是我做了什麼......
我把文本或HTML文件,(我會告訴文本,因爲它的小,但完全相同的代碼適用),我把衆所周知值放入文本文件中,稍後可以替換。
- 開始文本文件
We've generated a new password for you at your request, you can use this new password with your username to log in to various sections of our site.
Username: ##UserName##
Temporary Password: ##Password##
To use this temporary password, please copy and paste it into the password box.
Please keep this email for your records.
- 最終文本文件
那麼它的創建鍵/值對的列表,用文字簡單的事情進行替換,和值你用它來代替它。將文件作爲字符串加載到內存中,並循環訪問您的鍵/值對,替換您的文本值。
ListDictionary dictionary = new ListDictionary
{
{"##UserName##", user.BaseUser.UserName},
{"##Password##", newPassword}
};
string fromResources = GetFromResources("forgotpasswordEmail.html");
string textfromResources = GetFromResources("forgotpasswordEmail.txt");
foreach (DictionaryEntry entry in dictionary)
{
fromResources = fromResources.Replace(entry.Key.ToString(), entry.Value.ToString());
textfromResources = textfromResources.Replace(entry.Key.ToString(), entry.Value.ToString());
}
然後您可以通過電子郵件的文本,(在這種情況下,textfromResources變量),它將包含所有必要的換行和格式化。
就像我說過的,你可以用HTML文件或任何你想要的文件來做同樣的事情。儘管我的例子是在C#中(我沒有任何經典的ASP代碼方便,對不起),但查找和替換值的概念將適用於傳統的ASP。
嗚呼!正確的錢!你讓我今天一整天都感覺很好。我確信我在閱讀文件時錯過了一些東西。但是,我不小心以HTML格式發送電子郵件!再次感謝! – 2008-11-26 15:58:17