2010-08-18 75 views
0

在我的網絡應用程序中,當用戶發送有關該網站的任何評論時,該消息將發送到我的郵件(即[email protected])。雅迄今爲止工作正常,但當我點擊此轉發給任何人(在[email protected]轉發選項)它顯示與<html><body>標籤。我該如何解決這個問題。在asp.net中發送郵件?

private void sendingmail() 
{ 
    string filename = FileUpload1.FileName.Trim(); 
    string a = "http://www.begoniainfosys.com/Re/" + filename; 
    //string emailid = emailid.ToString(); 
    MailMessage m = new MailMessage(); 
    m.Subject = "Uploaded Resume"; 

    if (txtdesc.Text.ToString() == "") 
    { 
     m.Attachments.Add(new System.Net.Mail.Attachment(@Server.MapPath("~/Resumes/" + FileUpload1.FileName))); 
     m.Body = "<html><body><b>" + "The Name Of The JobSeeker:" + txtname.Text + "<br><br>" + "The MailID:" + txtemailid.Text + "<br><br>" + "The MobileNumber:" + txtmobile.Text + "<br><br>" + "The Postion Applied For:" + txtpositionapplied.Text + "</b> </body></html>"; 
     m.IsBodyHtml = true; 
    } 
    else 
    { 
     m.Attachments.Add(new System.Net.Mail.Attachment(@Server.MapPath("~/Resumes/" + FileUpload1.FileName))); 

     m.Body = "<html><body><b>" + "The Name Of JobSeeker:" + txtname.Text + "<br><br>" + "The MailID:" + txtemailid.Text + "<br><br>" + "The MobileNumber:" + txtmobile.Text + "<br><br>" + "The Postion Applied For:" + txtpositionapplied.Text +"<br><br>"+"The Description:"+txtdesc.Text.ToString()+" </b> </body></html>"; 
     m.IsBodyHtml = true; 
    } 

    string frm = txtemailid.Text; 
    m.From = new MailAddress(frm); 
    m.CC.Add(new MailAddress("[email protected]")); 
    m.To.Add(new MailAddress("[email protected]")); 
    m.Priority = MailPriority.High; 
    SmtpClient sm = new SmtpClient(); 
    sm.DeliveryMethod = SmtpDeliveryMethod.Network; 
    sm.Send(m); 
} 

回答

0

我建議你的電子郵件客戶端沒有在HTML編輯,所以當你轉發,它可能轉換爲富文本或許並不瞭解html標籤?

你有什麼樣的客戶端 - 只需要一個快速的谷歌搜索來了解如何確保它使用HTML格式的電子郵件。

在舊版本的Outlook中,它是工具 - >選項 - >郵件格式。

1

你現在這樣做的方式。您只提供電子郵件正文的HTML版本。如果發送給不支持html的電子郵件客戶端,則會顯示標籤。

相反,您應該發送包含html的備用視圖的純文本。這樣客戶端應用程序可以決定使用哪個版本。

var message = new System.Net.Mail.MailMessage(fromAddress, toAddress); 
message.Body = "plain text"; 
var htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(htmlBody, 
         new System.Net.Mime.ContentType("text/html")); 
message.AlternateViews.Add(htmlView);