2011-06-21 21 views
2

トランザクションを完了した顧客に電子メールを送信する必要がありますが、コードの後ろに書式をドラフトする際にいくつかの困難を抱えています。これはコードであり、明らかに1つの直線として表示されています私のメールの本文にテキストを、どのように私はそれが何かのように、任意のヘルプは高く評価されて表示されます、このような方法でそれをフォーマットすることができ、感謝:コードの電子メール書式

Thank you for shopping with us. Your purchase details are as follow: 

Product ID   Model Number   Model Name   Unit Cost Quantity ItemTotal 

357      P1  AK47 Rifle(free 30 * 7.62) $2.99   1  2.99 

362      XT3893  Mirage stealth tank  $500000.99  1 500000.99 


                       Total:$500002.99 

は、これは私のコードです:

   MembershipUserCollection users = Membership.GetAllUsers(); 
       MembershipUser u = users[UserName]; 

       MailMessage mail = new MailMessage(); 
       mail.To.Add(u.Email); 
       mail.From = new MailAddress("[email protected]"); 
       mail.Subject = "Purchase invoice" + newOrder.OrderID; 

       string bodyText = ""; 
       double unitQtyPrice = 0; 
       double totalPrice = 0; 
       foreach (var cItem in cartList) 
       { 
        Math.Round(cItem.UnitCost, 2); 

        bodyText = bodyText + '\n' 
           + cItem.ProductID.ToString() + '\t' 
           + cItem.ModelName + '\t' 
           + cItem.ModelNumber + '\t' 
           + cItem.UnitCost.ToString() + '\t' 
           + cItem.Quantity.ToString() + '\t'; 

        unitQtyPrice = cItem.Quantity * (double)cItem.UnitCost; 
        totalPrice += unitQtyPrice;   
       } 

       Math.Round(totalPrice, 2); 
       mail.Body = "Thank you for shopping with us. Your purchase details are as follow:" 
        + '\n' + "ProductID:" + '\t' + "ModelName" + '\t' + "ModelNumber" + '\t' + "UnitPrice" + '\t' + "Quantity" 
        + '\n' + bodyText + '\n' + '\n' + '\t' + '\t' + "Total Price:" + totalPrice ; 
       mail.IsBodyHtml = true; 
       SmtpClient client = new SmtpClient("smtp.live.com", 587); 
       client.EnableSsl = true; //ssl must be enabled for hotmail 
       NetworkCredential credentials = new NetworkCredential("[email protected]", "xxxx"); 
       client.Credentials = credentials; 
       try 
       { 
        client.Send(mail); 
       } 
       catch (Exception exp) 
       { 
        throw new Exception("ERROR: Fail to send email - " + exp.Message.ToString(), exp); 
       } 

答えて

4

あなたは空白を区別しないHTMLに設定してください。改行やすべてで平文として送信する場合は、IsBodyHtmlを設定しないでください。

また、電子メールのレイアウトに実際のHTMLマークアップを含めることもできます。これは、より良い解決策です。

1

だけ...あなたのHTML言語でmail.Body一部を書き

mail.IsBodyHtml = true; 
を設定
関連する問題