I am trying to send a pdf generated with Cystal:
rd.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, Server.MapPath("~\\Crystal\\TheExp.pdf"));
SendGridEmail em = new SendGridEmail();
var response = em.SendEmail("[email protected]", "[email protected]", "Memo", "This is it", Server.MapPath("~\\Crystal\\TheExp.pdf"),"TheExp.pdf");
Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
stream.Seek(0, SeekOrigin.Begin);
return File(stream, "application/pdf", "PaidInvoice" + invNumber.ToString() + ".pdf");
The code that sends the email works until I include the pdf
public string SendEmail(string to,string from, string subject, string content, string enclosure,string fileName)
{
var apiKey = "xx";// System.Environment.GetEnvironmentVariable("SendGridKey");
var client = new SendGridClient(apiKey);
var msg = new SendGridMessage();
msg.AddTo (new EmailAddress(to));
msg.SetSubject(subject);
msg.PlainTextContent =content;
msg.HtmlContent= content;
msg.From=new EmailAddress(from, "Tyres");
// this line breaks it
msg.AddAttachment(fileName, enclosure);
var response = client.SendEmailAsync(msg).ToString();
return response;
}
anyone any ideas. Enclosure is the path to the newly generated pdf. "~\Crystal\TheExp.pdf". It works fine without the line.
Jonathan