如何在dll中嵌入html文件并稍后编辑内容?
我对如何使用它没有足够的想法。
目标:
1) 在 dll 中嵌入 HTML 文件
html 的内容为:
美好的一天!
您收到这封电子邮件是因为有人使用此电子邮件地址请求找回密码。 请访问以下链接开始该过程:
点击下面的链接
基本网址{}如果您没有提出此类请求,请忽略此电子邮件。
最好, 网站管理员
2) 每次我必须发送此电子邮件时,我都必须在嵌入的 html 中查找“BaseUrl{}”并将其替换为用于验证的链接。
3)我必须以html文件的形式发送文件,因为在进一步的开发中,我必须将图像放入文件中。
发送电子邮件的代码:
using System.Net.Mail;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static void SendEmail(MailMessage mail)
{
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 123;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "strongpassword");
client.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
client.Send(mail);
}
private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
return true;
else
{
ServiceFault.WriteLog("Invalid SSL");
return true;
}
}
或者您可以给我教程链接,或者如果您有更好的建议,请告诉我。
谢谢!
I don't have enough idea on how to work with this.
Objective:
1) Embed HTML file in dll
Content of the html would be:
Good Day!
You received this email because a request was made for password retrieval with this email address.
Please go to the link below to start the process:Click the link below
BaseUrl{}Please ignore this email if you did not make such request.
Best,
Web Master
2) Everytime I have to send this email, I have to find and replace the "BaseUrl{}" with a link for verification inside the embeded html.
3) I have to send the file in a form of html file, beacause in further development, I will have to put images in the file.
Code for sending email:
using System.Net.Mail;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static void SendEmail(MailMessage mail)
{
SmtpClient client = new SmtpClient();
client.Host = "smtp.gmail.com";
client.Port = 123;
client.Credentials = new System.Net.NetworkCredential("[email protected]", "strongpassword");
client.EnableSsl = true;
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);
client.Send(mail);
}
private static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
return true;
else
{
ServiceFault.WriteLog("Invalid SSL");
return true;
}
}
Or you can give me links for tutorial, or if you have more better suggestion, please let me know.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为对 URI 使用字符串替换的策略很好。
为了将其嵌入到您的 DLL 中:
1) 创建一个包含您想要的内容的文件。
2) 将资源文件添加到您的项目中。
3) 添加“文件”类型资源(“添加现有文件”选项)并选择您的文件(这会将您的文件复制到您的项目中。
4) 在您的代码中,使用自动生成资源访问器访问该嵌入文件的内容。
I think the strategy of using string replacement for the URI is fine.
In order to embed this into you DLL:
1) Create a file with the content you want.
2) Add a Resources file to your project.
3) Add a "File" type resource (the Add Existing File option) and select your file (which will copy your file into your project.
4) In your code, access the content of that embedded file using the auto-generate resource accessor.
要将文件嵌入到 DLL 中(我假设您使用的是 Visual Studio),请在“解决方案资源管理器”选项卡中,右键单击项目或文件夹,然后转到“添加”->“现有项目” ...,然后将您的文件添加到解决方案中。从那里,右键单击该文件,然后单击“属性”。从那里,为“构建操作”属性选择“嵌入式资源”
从那里,您可以将文件作为字符串读取。
我会将“BaseUrl{}”更改为
{0}
,如果您将文件作为字符串读取,请使用以下代码进行替换:从那里您可以添加
email
字符串作为您的消息,一切都很好!看起来应该有效!
To embed a file into your DLL (and I'm assuming you are using Visual Studio), in the "Solution Explorer" tab, right click on the project or a folder and go
Add->Existing Item...
and then add your file to the solution. From there, right click on the file and click "Properties". From there, choose "Embedded Resource" for the "Build Action" propertyFrom there, you can read the file in as a string.
I would change "BaseUrl{}" to
{0}
and if you read the file in as a string, use this code to do a replace:From there you can add the
email
string as your message and all is good!That looks like it should work!