【问题标题】:how to send html templates in asp.net 4.0如何在 asp.net 4.0 中发送 html 模板
【发布时间】:2012-04-27 05:42:52
【问题描述】:
Emailservicerequest.Email = new Email();
            Emailservicerequest.Email.FromEmail = Insertcampaignrequest.Campaign.SenderAddress;
            Emailservicerequest.Email.ToEmail = Insertcampaignrequest.Campaign.RecipientsFilter;
            Emailservicerequest.Email.Subject = Insertcampaignrequest.Campaign.Subject;

           // Emailservicerequest.Email = true;

            Emailservicerequest.Email.Body = Convert.ToString(MailFormat.Html);
            Emailservicerequest.Email.Body = "Provider/EmailTemplate/email.html";
 Emailserviceresponse=Emailservice.SendEmail(Emailservicerequest);

【问题讨论】:

    标签: asp.net wcf c#-4.0


    【解决方案1】:

    在 Asp.net 4.0 中,您应该使用 T4 模板来创建电子邮件模板。它简单且易于管理。

    了解更多信息 http://asmiki.com/2011/05/20/using-t4-templates-for-compiling-net-email-templates/

    问候

    【讨论】:

      【解决方案2】:

      要将您的 HTML 文件转换为字符串,以便您可以将其设置为电子邮件对象的正文值,您可以使用以下函数:

      public string ReturnHTML(string Path)
           {
               string strBody = "";
               try
                  {
                      StreamReader objReader = new StreamReader(Path);
                      strBody = objReader.ReadToEnd();
                      objReader.Close();
                  }
               catch (Exception ex)
                  {
                      strBody = "";
                      throw ex;
                  }
                  return strBody;
           }
      

      在你的代码中调用上述函数

      string path = Server.MapPath(ConfigurationManager.AppSettings["NoticeApprovalPath"].ToString());
      string tempStr = cmm.ReturnHTML(path);
      tempStr = tempStr.Replace("[xxxNoticeIDxxx]", Convert.ToString(RequestID));
      

      replace 函数用于替换 HTML 模板中的值:

      这里[xxxNoticeIDxxx] 被替换为包含数据的值RequestID 变量。

      【讨论】:

        猜你喜欢
        • 2018-01-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-06-19
        • 1970-01-01
        • 2011-11-03
        • 2019-06-11
        • 2017-12-26
        相关资源
        最近更新 更多