2016-06-07 2 views
0

Ich erstelle E-Mails, die Techniker geschickt werden muss. Es gibt ungefähr 12 E-Mails (je nach ausgewähltem Druckermodell wird nur eine gesendet). Die E-Mails senden alles gut aus. Das einzige Problem, das ich habe, ist, dass die Bilder nicht angezeigt werden, sie werden als Anhänge mit einer .bin Erweiterung angezeigt. Ich verwende eine case-Anweisung, um die E-Mails zu versenden. Jede Hilfe bei dem, was ich falsch mache, wird sehr geschätzt. Vielen Dank. DieseBilder nicht in E-Mail-Anzeige (zeigt als .bin)

ist, wie mein Code wie folgt aussieht:

Falls Aussage:

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

Dieser Code innerhalb einer case-Anweisung von Verzug ist. Außerhalb der Fall füge ich die smtp Details:

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

Dies ist, was meine E-Mail-Methode wie folgt aussieht:

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(); 
    } 

Antwort

0

statt Server.MapPath Pfad Verwendung Website, um die Bilder zu bekommen

Verwandte Themen