Hi,
I am using crystal reports to create a pdf attachment and send it by email. I don't get any errors when i run the code but I don't receive the email either.
Thank you in advance.
Here's my code as follows.
private void sendEmail()
{
MailMessage message = new MailMessage();
SmtpClient smtp = new SmtpClient();
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(@"C:\test\report1.rpt");
cryRpt.SetDatabaseLogon("username", "pass");
Stream stream = cryRpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
byte[] file = new byte[stream.Length];
stream.Read(file, 0, (int)stream.Length);
stream.Close();
message.From = new MailAddress("a@a.com");
message.To.Add(new MailAddress("b@b.com"));
message.Subject = "Subject";
message.Body = "Body";
message.IsBodyHtml = true;
if (file != null)
{
message.Attachments.Add(new Attachment(new MemoryStream(file), "attachment.pdf"));
}
smtp.Send(message);
}