2017-02-14 20 views
0

Senden der E-Mail und der Anhang actaly funktioniert. mein Problem ist, ich diese Fehlermeldung erhalten, wenn sie versuchen, die „erzeugte pdf“Mail pdf Anhang mit Rotativa

Eine Ausnahme vom Typ ‚System.Exception‘ in Rotativa.dll aufgetreten zu senden, aber wurde in Benutzercode

Zusätzliche Informationen nicht behandelt: Fehler: fehlgeschlagen Lade Seite http://localhost:49224/Offer/OfferPdf/4 (manchmal wird es funktioniert nur diesen Fehler mit --load-Fehlerbehandlung ignorieren ignorieren)

der E-Mail-Test in der Steuerung:

public ActionResult MailTest() 
    { 



     MailMessage msg = new MailMessage(); 
     msg.To.Add(new MailAddress(CoEmail)); 
     msg.From = new MailAddress(MailFrom, UserName); 
     msg.Subject = "Offer"; 
     msg.Body = "This is a Test"; 
     MemoryStream stream = new MemoryStream(OffersPdfMail (4, "Offer")); 
     Attachment att1 = new Attachment(stream, "Offer.pdf", "application/pdf"); 
     msg.Attachments.Add(att1); 
     msg.IsBodyHtml = true; 
     msg.BodyEncoding = System.Text.Encoding.UTF8; 
     msg.SubjectEncoding = System.Text.Encoding.Default; 

     SmtpClient client = new SmtpClient(); 
     client.UseDefaultCredentials = false; 
     client.Credentials = new System.Net.NetworkCredential(User, Pass); 
     client.Port = 587; // 
     client.Host = "smtp.office365.com"; 
     client.DeliveryMethod = SmtpDeliveryMethod.Network; 
     client.EnableSsl = true; 
     try 
     { 
      client.Send(msg); 
      return RedirectToAction("index"); 

     } 
     catch (Exception ex) 
     { 
      return HttpNotFound(); 
     } 

    } 

die Byte []:

public Byte[] OfferPdfMail(int? id, string filename) 
    { 
    var mailpdft = new ActionAsPdf("OfferPdf/4") 
     { 
      FileName = "Offer", 
      PageSize = Rotativa.Options.Size.A4, 






      PageWidth = 210, 

      PageHeight = 297 

     }; 
     Byte[] PdfData = mailpdft.BuildPdf(ControllerContext); 
     return PdfData; 

und zuletzt das ViewasPdf:

 public ActionResult OfferPdf (int? id, string filename) 
    { 
     string footer = "test" ; 
     if (id == null) 
     { 
      return new HttpStatusCodeResult(HttpStatusCode.BadRequest); 
     } 




     var pdf = new ViewAsPdf("TilbudsPdf") { 
      FileName = filename, 
      PageSize = Rotativa.Options.Size.A4, 

      PageOrientation = Rotativa.Options.Orientation.Portrait, 

      PageMargins = new Rotativa.Options.Margins(12, 12, 12, 12),// it’s in millimeters 

      PageWidth = 210, 

      PageHeight = 297, 
      CustomSwitches = footer }; 

     return pdf; 
    } 

Editted die Namen auf Englisch. vielleicht etwas verpasst haben. Vielen Dank für Ihre Geduld und Entschuldigung für das schlechte Englisch. Mit freundlichen Grüßen Eric

Antwort

0

Ich fand eine Lösung, es war, weil ich dumm war, zu versuchen, ein pdf von einem pdf zu machen. so machte ich eine neue Action Methode wie folgt:

public ActionResult tilbudspdfMailView(int? id, string filename) 
    { 
     Offer Offer= db.Offer.Find(id); 

     return View("OfferPdf", Offer); 
}