I'm using a preformatted text file as a template for emails. The file has line breaks where I want them. I'd like to use this template to send a plain text email, but when I do I'm losing all formatting. Line breaks are stripped.
我正在使用预先格式化的文本文件作为电子邮件的模板。该文件在我想要的地方有换行符。我想使用此模板发送纯文本电子邮件,但是当我这样做时,我将丢失所有格式。换行被剥离。
How do I parse this file and retain line breaks? I don't want to use a <pre>
tag because I want to send plain text emails.
如何解析此文件并保留换行符?我不想使用
标签,因为我想发送纯文本电子邮件。
I'm using the classic ASP ReadAll method to pull the template into a string:
我正在使用经典的ASP ReadAll方法将模板拉成字符串:
Dim TextStream
Set TextStream = FSO.OpenTextFile(Filepath, ForReading, False, TristateUseDefault)
' Read file in one hit
Dim Contents
GetTemplate = TextStream.ReadAll ' return file contents
What am I missing?
我错过了什么?
3 个解决方案
#1
1
The code you show shouldn't strip any line breaks. The problem is probably on the email generation part. Could you show that part?
您显示的代码不应删除任何换行符。问题可能出在电子邮件生成部分。你能展示那部分吗?
Is the mail's Content-Type: text/plain?
邮件的内容类型是:text / plain吗?
#2
3
this is what I have done...
这就是我所做的......
I take a text, or HTML file, ( I'll show text, since its smaller, but the exact same code applies ), and I put well know values into the text file that I can later replace.
我采用文本或HTML文件(我将显示文本,因为它较小,但完全相同的代码适用),并且我将熟知的值放入文本文件中,以后我可以替换。
-- Begin Text File
- 开始文本文件
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.
-- End Text File
- 结束文本文件
Then its a simple matter of creating a list of key/value pairs, with the text to be replaced, and the value your replacing it with. Load the file into memory as a string, and loop through your key/value pair replacing your text values.
然后简单的事情是创建一个键/值对列表,包含要替换的文本,以及替换它的值。将文件作为字符串加载到内存中,并循环键入/值对,替换文本值。
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());
}
Then you can email the text, ( in this case the textfromResources variable ), and it will contain all of the necessary line breaks and formatting.
然后您可以通过电子邮件发送文本(在本例中为textfromResources变量),它将包含所有必要的换行符和格式。
Like I said, you can do this eact same thing with HTML files, or any type of file you want to.
就像我说的,你可以用HTML文件或你想要的任何类型的文件做同样的事情。
Although my example is in C#, ( I don't have any classic ASP code handy, sorry ), the concept of finding and replacing values will apply to classic ASP.
虽然我的例子是在C#中,(我没有任何经典的ASP代码,对不起),查找和替换值的概念将适用于经典的ASP。
#3
0
I would recommend using http://www.webdevbros.net/2007/06/28/template-component-for-classic-asp/
我建议使用http://www.webdevbros.net/2007/06/28/template-component-for-classic-asp/
#1
1
The code you show shouldn't strip any line breaks. The problem is probably on the email generation part. Could you show that part?
您显示的代码不应删除任何换行符。问题可能出在电子邮件生成部分。你能展示那部分吗?
Is the mail's Content-Type: text/plain?
邮件的内容类型是:text / plain吗?
#2
3
this is what I have done...
这就是我所做的......
I take a text, or HTML file, ( I'll show text, since its smaller, but the exact same code applies ), and I put well know values into the text file that I can later replace.
我采用文本或HTML文件(我将显示文本,因为它较小,但完全相同的代码适用),并且我将熟知的值放入文本文件中,以后我可以替换。
-- Begin Text File
- 开始文本文件
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.
-- End Text File
- 结束文本文件
Then its a simple matter of creating a list of key/value pairs, with the text to be replaced, and the value your replacing it with. Load the file into memory as a string, and loop through your key/value pair replacing your text values.
然后简单的事情是创建一个键/值对列表,包含要替换的文本,以及替换它的值。将文件作为字符串加载到内存中,并循环键入/值对,替换文本值。
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());
}
Then you can email the text, ( in this case the textfromResources variable ), and it will contain all of the necessary line breaks and formatting.
然后您可以通过电子邮件发送文本(在本例中为textfromResources变量),它将包含所有必要的换行符和格式。
Like I said, you can do this eact same thing with HTML files, or any type of file you want to.
就像我说的,你可以用HTML文件或你想要的任何类型的文件做同样的事情。
Although my example is in C#, ( I don't have any classic ASP code handy, sorry ), the concept of finding and replacing values will apply to classic ASP.
虽然我的例子是在C#中,(我没有任何经典的ASP代码,对不起),查找和替换值的概念将适用于经典的ASP。
#3
0
I would recommend using http://www.webdevbros.net/2007/06/28/template-component-for-classic-asp/
我建议使用http://www.webdevbros.net/2007/06/28/template-component-for-classic-asp/