2012-04-27 43 views
0
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); 

回答

0

到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)); 

替換功能是用來取代在HTML模板的值:

[xxxNoticeIDxxx]這裏被替換爲包含數據的值RequestID變量。