2016-06-07 135 views
0

我正在創建必須發送給技術人員的電子郵件。大約有12封電子郵件(根據所選擇的打印機型號,僅發送一封)。電子郵件一切都很好。我遇到的唯一問題是圖像不顯示,它們以附件擴展名爲.bin。我正在使用案例陳述來發送電子郵件。任何幫助我做錯了將不勝感激。謝謝。圖像不在電子郵件中顯示(顯示爲.bin)

這是我的代碼看起來像:

在case語句:

string headerPath = Server.MapPath("~\\Images\\EmailImages\\1022_03.png"); 
      LinkedResource img1022_03 = new LinkedResource(headerPath); 
      img1022_03.ContentId = "1022_03"; 

      string tonerPath = Server.MapPath("~\\Images\\EmailImages\\TonerSignature.png"); 
      LinkedResource TonerSignature = new LinkedResource(tonerPath); 
      TonerSignature.ContentId = "TonerSignature"; 

      string img1022_11Path = Server.MapPath("~\\Images\\EmailImages\\1022_11.png"); 
      LinkedResource img1022_11 = new LinkedResource(img1022_11Path); 
      img1022_11.ContentId = "1022_11"; 

      AlternateView avDefault = AlternateView.CreateAlternateViewFromString(SendOMD(), null, MediaTypeNames.Text.Html); 
      avDefault.LinkedResources.Add(img1022_03); 
      avDefault.LinkedResources.Add(TonerSignature); 
      avDefault.LinkedResources.Add(img1022_11); 
      Mail.AlternateViews.Add(avDefault); 

此代碼是默認的case語句裏面。外面的情況下,我添加的smtp細節:

 System.Configuration.Configuration configurationFile = WebConfigurationManager.OpenWebConfiguration("~/web.config"); 
     MailSettingsSectionGroup mailSettings = configurationFile.GetSectionGroup("system.net/mailSettings") as MailSettingsSectionGroup; 
     if (mailSettings != null) 
     { 
      int port = mailSettings.Smtp.Network.Port; 
      string host = mailSettings.Smtp.Network.Host; 
      string password = mailSettings.Smtp.Network.Password; 
      string username = mailSettings.Smtp.Network.UserName; 
     } 
     SmtpClient SMTP = new SmtpClient(); 
     SMTP.Send(Mail); 

這是我的電子郵件的方法是什麼樣子:

private string SendOMD() 
    { 
     string techType = radTechnicianType.SelectedValue.ToString(); 
     string techString = ""; 

     if (techType == "Field Technician") 
      techString = "Please send a technician to replace the toner on the above mentioned machine."; 
     else if (techType == "Onsite technician") 
      techString = "Please replace the toner on the above mentioned machine."; 
     else 
      techString = "Please send a technician to replace the toner on the above mentioned machine."; 

     StringBuilder stringBuilt = new StringBuilder(); 

     stringBuilt.AppendLine(@"<style type=""text/css"">"); 
     stringBuilt.AppendLine(".divStyle { font-family:Verdana,sans-serif, Arial, Helvetica; font-size:10pt; font-weight: bold; }"); 
     stringBuilt.AppendLine(".par { font-family:Verdana,sans-serif, Arial, Helvetica; font-size:10pt; width:658px; }"); 
     stringBuilt.AppendLine("table { border: 1px solid #000; border-collapse: collapse; font-family:Verdana; font-size:10pt; background-color:#dcdcdc; }"); 
     stringBuilt.AppendLine("table td { border-left: 1px solid #000; font-family:Verdana,sans-serif, Arial, Helvetica; font-size:10pt; background-color:snow; border-bottom: 1px solid #000; padding-left:2px; margin-left:2px; padding-right:5px; margin-right:5px; }"); 
     stringBuilt.AppendLine("table td:first-child { border-left: none; font-family:Verdana,sans-serif, Arial, Helvetica; font-size:10pt; background:#dcdcdc; background-color:#dcdcdc; border-bottom: 1px solid #000; }"); 
     stringBuilt.AppendLine("</style>"); 

     stringBuilt.AppendLine(@"<img alt="" src=""cid:1022_03"" width=""817"" height=""123"" />"); 
     stringBuilt.AppendLine("<br/>"); 

     stringBuilt.AppendLine(@"<p class=""par"">Dear " + txtClient.Text.Trim() + ",</p>"); 

     stringBuilt.AppendLine("Details:"); 
     stringBuilt.AppendLine("<br/>"); 

     stringBuilt.AppendLine("<table>"); 
     stringBuilt.AppendLine(@"<tr><td style=""background-color:#dcdcdc; widht:350px;"" >Model: </td><td style=""widht:250px;""> " + lstModelType.SelectedValue.ToString() + " </td></tr>"); 
     stringBuilt.AppendLine(@"<tr><td style=""background-color:#dcdcdc; widht:350px;"" >Serial No: </td><td style=""widht:250px;""> " + txtSerial.Text.Trim() + " </td></tr>"); 
     stringBuilt.AppendLine(@"<tr><td style=""background-color:#dcdcdc; widht:350px;"" >IP Address: </td><td style=""widht:250px;""> " + txtIPAddress.Text.Trim() + " </td></tr>"); 
     stringBuilt.AppendLine(@"<tr><td style=""background-color:#dcdcdc; widht:350px;"" >AD Sharename: </td><td style=""widht:250px;""> " + txtADSharename.Text.Trim() + " </td></tr>"); 
     stringBuilt.AppendLine(@"<tr><td style=""background-color:#dcdcdc; widht:350px;"">Department: </td><td style=""widht:250px;""> " + txtDepartment.Text.Trim() + " </td></tr>"); 
     stringBuilt.AppendLine(@"<tr><td style=""background-color:#dcdcdc; widht:350px;"">Colour: </td><td style=""widht:250px;""> " + lstColour.SelectedValue.ToString() + " </td></tr>"); 
     stringBuilt.AppendLine("</table>"); 

     stringBuilt.AppendLine(@"<p class=""par""><em>" + techString + "</em></p>"); 
     stringBuilt.AppendLine("<br/>"); 

     stringBuilt.AppendLine(@"<div class=""divStyle""> Regards, "); 
     stringBuilt.AppendLine("<br/>"); 
     stringBuilt.AppendLine(lstApprover.SelectedValue.ToString()); 
     stringBuilt.AppendLine("</div>"); 
     stringBuilt.AppendLine(@"<img alt="" src=""cid:TonerSignature"" width=""300"" height=""70"" />"); 

     stringBuilt.AppendLine("<br/>"); 
     stringBuilt.AppendLine(@"<img alt="" src=""1022_11"" width=""815"" height=""54"" />"); 

     return stringBuilt.ToString(); 
    } 

回答

0

,而不是使用使用Server.Mappath網站路徑來獲取圖像

相關問題