How to get Confirmation message when i sent pdf as mail in asp.net
-
Hi all, I am using Local reports(RDLC) for my reports in Asp.net I am have the following code in my button.I am able to send my pdf report as mail,and every thing is ok, But Problem is I am unable to produce a Confirmation message,like "Mail sent successfully".How could i change my code.Pls help me Very Urgent. Here it is skipping message.I am directly getting preview and sending mail. Private Sub BTN_ITCLETMAIL_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_ITCLETMAIL.Click Dim PrefAddrid As String = DDL_COMMUADDRS.SelectedValue Dim rep As LocalReport = ReportViewer2.LocalReport Dim Balmail As New Bal_EmailForm RegisNum = Trim(LblItcRegNum.Text) Dim conn As New SqlConnection(conString) Dim da As New SqlDataAdapter Dim ds As New ReportDataSource Dim row As GridViewRow = Nothing Dim Chkcount As Integer = 0 Dim intStatus As Integer ' ''For PDF Dim warnings As Warning() = Nothing Dim streamids As String() = Nothing Dim mimeType As String = Nothing Dim encoding As String = Nothing Dim extension As String = Nothing Dim bytes As Byte() Dim FolderLocation As String 'Dim FLAG_VIE_REPORT As String '' ==================== FolderLocation = Path.GetTempPath Dim filepath As String = FolderLocation & RegisNum & "ITCLetter.pdf" Try File.Delete(filepath) Session.Contents.Remove("Error") rep.ReportPath = System.AppDomain.CurrentDomain.BaseDirectory & "ReportRdlcs\ITCLetter.rdlc" Dim cmd As SqlCommand = New SqlCommand("RepGetOnlyAdderssDataForDemandLetter", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@RegistrationNumber", RegisNum) cmd.Parameters.AddWithValue("@PrefContactAdderss", PrefAddrid) da.SelectCommand = cmd myDataSet.Clear() da.Fill(myDataSet, "RepGetOnlyAdderssDataForDemandLetter") ds.Name = "AddressDetforDemandLetter_RepGetOnlyAdderssDataForDemandLetter" ds.Value = myDataSet.Tables(0) rep.DataSources.Add(ds) Dim params(3) As Microsoft.Reporting.WebForms.ReportParameter Dim strDemStudName As String = Nothing strDemStudName = Trim(LBL_CLIENT.Text) Dim p1 As Microsoft.Reporting.WebForms.ReportParameter
-
Hi all, I am using Local reports(RDLC) for my reports in Asp.net I am have the following code in my button.I am able to send my pdf report as mail,and every thing is ok, But Problem is I am unable to produce a Confirmation message,like "Mail sent successfully".How could i change my code.Pls help me Very Urgent. Here it is skipping message.I am directly getting preview and sending mail. Private Sub BTN_ITCLETMAIL_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTN_ITCLETMAIL.Click Dim PrefAddrid As String = DDL_COMMUADDRS.SelectedValue Dim rep As LocalReport = ReportViewer2.LocalReport Dim Balmail As New Bal_EmailForm RegisNum = Trim(LblItcRegNum.Text) Dim conn As New SqlConnection(conString) Dim da As New SqlDataAdapter Dim ds As New ReportDataSource Dim row As GridViewRow = Nothing Dim Chkcount As Integer = 0 Dim intStatus As Integer ' ''For PDF Dim warnings As Warning() = Nothing Dim streamids As String() = Nothing Dim mimeType As String = Nothing Dim encoding As String = Nothing Dim extension As String = Nothing Dim bytes As Byte() Dim FolderLocation As String 'Dim FLAG_VIE_REPORT As String '' ==================== FolderLocation = Path.GetTempPath Dim filepath As String = FolderLocation & RegisNum & "ITCLetter.pdf" Try File.Delete(filepath) Session.Contents.Remove("Error") rep.ReportPath = System.AppDomain.CurrentDomain.BaseDirectory & "ReportRdlcs\ITCLetter.rdlc" Dim cmd As SqlCommand = New SqlCommand("RepGetOnlyAdderssDataForDemandLetter", conn) cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@RegistrationNumber", RegisNum) cmd.Parameters.AddWithValue("@PrefContactAdderss", PrefAddrid) da.SelectCommand = cmd myDataSet.Clear() da.Fill(myDataSet, "RepGetOnlyAdderssDataForDemandLetter") ds.Name = "AddressDetforDemandLetter_RepGetOnlyAdderssDataForDemandLetter" ds.Value = myDataSet.Tables(0) rep.DataSources.Add(ds) Dim params(3) As Microsoft.Reporting.WebForms.ReportParameter Dim strDemStudName As String = Nothing strDemStudName = Trim(LBL_CLIENT.Text) Dim p1 As Microsoft.Reporting.WebForms.ReportParameter
do one thing see the code and match your code (code is in C# syntax). //code public static bool SendMail(string FromEmail, string FromName, string ToEmails, string MailBody, string Subject, string CcEmails, string BccEmails, bool IsBodyHtml) { try { System.Net.Mail.MailMessage objMail = new System.Net.Mail.MailMessage(); //Mail From Field if (!String.IsNullOrEmpty(FromName)) { objMail.From = new MailAddress(FromEmail, FromName); } else { objMail.From = new MailAddress(FromEmail); } //Mail To Field if (!String.IsNullOrEmpty(ToEmails)) { objMail.To.Add(ToEmails); } //Mail Cc Field if (!String.IsNullOrEmpty(CcEmails)) { objMail.CC.Add(CcEmails); } //Mail Bcc Field if (!String.IsNullOrEmpty(BccEmails)) { objMail.Bcc.Add(BccEmails); } //Mail Subject Field objMail.Subject = Subject; //Mail Body Field objMail.Body = MailBody; objMail.IsBodyHtml = IsBodyHtml; try { SmtpClient smtp1 = new SmtpClient(); smtp1.Send(objMail); return true; } catch (Exception ex) { //HttpContext.Current.Response.Write(ex.Message.ToString()); return false; } } catch (Exception ex) { string mess = ex.Message.ToString(); return false; } } // now in your code if its return true then fire your script. it will show the message as if your script is without error.
Regards Keyur Satyadev
-
do one thing see the code and match your code (code is in C# syntax). //code public static bool SendMail(string FromEmail, string FromName, string ToEmails, string MailBody, string Subject, string CcEmails, string BccEmails, bool IsBodyHtml) { try { System.Net.Mail.MailMessage objMail = new System.Net.Mail.MailMessage(); //Mail From Field if (!String.IsNullOrEmpty(FromName)) { objMail.From = new MailAddress(FromEmail, FromName); } else { objMail.From = new MailAddress(FromEmail); } //Mail To Field if (!String.IsNullOrEmpty(ToEmails)) { objMail.To.Add(ToEmails); } //Mail Cc Field if (!String.IsNullOrEmpty(CcEmails)) { objMail.CC.Add(CcEmails); } //Mail Bcc Field if (!String.IsNullOrEmpty(BccEmails)) { objMail.Bcc.Add(BccEmails); } //Mail Subject Field objMail.Subject = Subject; //Mail Body Field objMail.Body = MailBody; objMail.IsBodyHtml = IsBodyHtml; try { SmtpClient smtp1 = new SmtpClient(); smtp1.Send(objMail); return true; } catch (Exception ex) { //HttpContext.Current.Response.Write(ex.Message.ToString()); return false; } } catch (Exception ex) { string mess = ex.Message.ToString(); return false; } } // now in your code if its return true then fire your script. it will show the message as if your script is without error.
Regards Keyur Satyadev
Hi,Thanks for reply, I am able to view message in other situations like inserting or updatating tables. I am unable to get message in this particular scenario,when i render a rdlc report into pdf. Regards, Naren