As your given solution, i tried to send email below followded your link
Export RDLC Report to PDF and send in Email as Attachment using C# and VB.Net in ASP.Net
there is not error is coming, i also debug but code is working fine, email address and credential fine, on Gridview email send
private void LoadReport()
{
con.Open();
SqlCommand cmd = new SqlCommand("[usp_Attendance_Register]", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@DateFrom", txtDateFrom.Text);
cmd.Parameters.AddWithValue("@DateTo", txtDateTo.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet1";
rds.Value = ds.Tables[0];
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.ReportPath = "Timeregistr.rdlc";
ReportViewer1.LocalReport.DataSources.Add(rds);
ReportViewer1.LocalReport.Refresh();
ReportViewer1.Visible = true;
con.Close();
}
for send email
protected void Email(object sender, EventArgs e)
{
using (MailMessage mm = new MailMessage("xxxx@gmail.com", "axxx86@gmail.com"))
{
mm.Subject = "RDLC Report PDF example";
mm.Body = "RDLC Report PDF example";
mm.Attachments.Add(new Attachment(ExportReportToPDF(Server.MapPath("~/Excel/"), "Invoice.pdf")));
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.sd-usedclothing.com";
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = "xx@sd-usexdxxxx.com";
NetworkCred.Password = "xxxxx";
smtp.UseDefaultCredentials = false;
smtp.EnableSsl = false;
smtp.Credentials = NetworkCred;
smtp.Port = 25;
smtp.Send(mm);
}
}
// Generate repord in a path
private string ExportReportToPDF(string path, string reportName)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string filenameExtension;
byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out filenameExtension, out streamids, out warnings);
string filename = path + reportName;
using (var fs = new System.IO.FileStream(filename, System.IO.FileMode.Create))
{
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}
return filename;
}