C# <;邮件定义>;及<;%%&燃气轮机;占位符

C# <;邮件定义>;及<;%%&燃气轮机;占位符,c#,asp.net,asp.net-membership,C#,Asp.net,Asp.net Membership,。。。 BodyFileName属性引用包含邮件正文文本的磁盘文件。如果我们将占位符和放在正文文本文件(RegistrationMail.txt)中,则CreateUserWizard将自动用已创建用户的用户名和密码替换这些占位符 A) 如果我想创建一个控件,该控件还可以用一些文本替换文件中的占位符,我该如何做 B) 我还可以从代码隐藏文件写入这些占位符吗?也就是说,是否有方法在调用时将特定文本写入某个txt文件中的占位符 thanx在SendingMail事件中调用一个简单的字符串.Re

。。。


BodyFileName属性引用包含邮件正文文本的磁盘文件。如果我们将占位符
放在正文文本文件(RegistrationMail.txt)中,则CreateUserWizard将自动用已创建用户的用户名和密码替换这些占位符

A) 如果我想创建一个控件,该控件还可以用一些文本替换文件中的占位符
,我该如何做

B) 我还可以从代码隐藏文件写入这些占位符吗?也就是说,是否有方法在调用时将特定文本写入某个txt文件中的占位符


thanx

在SendingMail事件中调用一个简单的字符串.Replace()可以实现这一功能

protected void CreateUserWizard1_SendingMail( object sender, MailMessageEventArgs e )
{
    // Replace <%foo%> placeholder with foo value
    e.Message.Body = e.Message.Body.Replace( "<%foo%>", foo );
}
受保护的void CreateUserWizard1\u发送邮件(对象发送者,MailMessageEventArgs e)
{
//用foo值替换占位符
e、 Message.Body=e.Message.Body.Replace(“,foo”);
}
创建自己的电子邮件机制也不是那么困难

using( MailMessage message = new MailMessage() )
{
    message.To.Add( "none@none.com" );
    message.Subject = "Here's your new password";
    message.IsBodyHtml = true;
    message.Body = GetEmailTemplate();

    // Replace placeholders in template.
    message.Body = message.Body.Replace( "<%Password%>", newPassword );
    message.Body = message.Body.Replace( "<%LoginUrl%>", HttpContext.Current.Request.Url.GetLeftPart( UriPartial.Authority ) + FormsAuthentication.LoginUrl ); // Get the login url without hardcoding it.

    new SmtpClient().Send( message );
}

private string GetEmailTemplate()
{
    string templatePath = Server.MapPath( @"C:\template.rtf" );

    using( StreamReader sr = new StreamReader( templatePath ) )
        return sr.ReadToEnd();
}
使用(MailMessage=newmailmessage())
{
message.To.Add(“none@none.com" );
message.Subject=“这是您的新密码”;
message.IsBodyHtml=true;
message.Body=GetEmailTemplate();
//替换模板中的占位符。
message.Body=message.Body.Replace(“,newPassword”);
message.Body=message.Body.Replace(“,HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)+FormsAuthentication.LoginUrl);//获取登录Url而不必硬编码。
新建SmtpClient().Send(消息);
}
私有字符串GetEmailTemplate()
{
字符串templatePath=Server.MapPath(@“C:\template.rtf”);
使用(StreamReader sr=新StreamReader(templatePath))
返回sr.ReadToEnd();
}