Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello everyone.

i have a project am working on, all i wanted to do i created a crystal report but what i want to do is, i want the crystal report created to send as an pdf mail to the recipient without having to view it, it should just send as a mail at a click. below is my code

C#
{
    MealTicket ticket = new MealTicket ();
    DataSet ds = new DataSet ();
    frmShowTicket ticketfrm = new frmShowTicket();
    rptTicket rpttik = new rptTicket ();
    string ticketno;
    ticketno = textBox4.Text;
    ds = ticket.GetTicket(ticketno);
    if (ds.Tables[0].Rows.Count > 0)
    {
        rpttik.SetDataSource(ds.Tables[0].DefaultView);
        ticketfrm.crv.ReportSource = rpttik;
        ticketfrm.Show();
    }
    else
    {
        MessageBox.Show("No Ticket to generate or Ticket ID is incorrect");
    }

    button1.Enabled = true;
    button2.Enabled = true;
    textBox1.Text = "";
    comboBox1.Text = "";
    comboBox2.Text = "";
    textBox3.Text = "";
    textBox4.Text = "";

}


What I have tried:

I dont know how to go about it but here is my code of sending mail which is working fine but how can i add the crystal report to the mail as an attachement.

This is an example of one my way of sending email and this is working fine

private void Button1_Click(object sender, EventArgs e)
{

if (txtEmail.Text == "")
{
MessageBox.Show("Enter your email", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtEmail.Focus();
return;
}
try
{
Cursor = Cursors.WaitCursor;
timer1.Enabled = true;
DataSet ds = new DataSet();
SqlConnection con = new SqlConnection(cs.DBcon);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT Password FROM User_Registration Where Email = '" + txtEmail.Text + "'", con);

SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
con.Close();
if (ds.Tables[0].Rows.Count > 0)
{
string recipient;
recipient = txtEmail.Text;
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress("jinny@gmail.com");
// Recipient e-mail address.
Msg.To.Add(recipient);
Msg.Subject = "Your Password Details";
Msg.Body = "Your Password is: " + Convert.ToString(ds.Tables[0].Rows[0]["Password"]) + "";
Msg.IsBodyHtml = true;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("jinny@gmail.com", "Pass");
smtp.EnableSsl = true;
smtp.Send(Msg);
MessageBox.Show(("Password Successfully sent " + ("\r\n" + "Please check your mail")), "Thank you", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Hide();
st1 = lblUser.Text;
st2 = "Password Is Recovered";
cf.LogFunc(st1, System.DateTime.Now, st2);
frmLogin LoginForm1 = new frmLogin();
LoginForm1.Show();
LoginForm1.UserID.Text = "";
LoginForm1.Password.Text = "";
LoginForm1.cmbUsertype.Text = "";
LoginForm1.ProgressBar1.Visible = false;

LoginForm1.cmbUsertype.Focus();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Posted
Updated 27-May-16 21:08pm

You can't add a CR report to an email and send it. You CAN, however, export the report to a PDF and send that as an attachment.

Another option is to send the recipient a link to a website that will generate the report so long as your site supports rendering a CR Report using some kind of data from a URL to tell it which report and any other information required by that particular user.
 
Share this answer
 
Hi!!!

below link will explain you how to Convert Crystal Report to PDF
crystal report to pdf

for sending email with attachement use below method

C#
private void SendEmail(string pdfpath,string mailfrom,string mailto) 
{
    try
    {
        MailMessage m = new MailMessage();
        System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient();

        m.From = new System.Net.Mail.MailAddress(mailfrom);
        m.To.Add(mailto);

        m.Subject = "Your Subject";


        // what I must do for sending a pdf with this email 

        m.Body = "Your Body";
        m.Attachments.Add(new Attachment(pdfpath));
        sc.Host = "Youyr Host"; // here is the smt path

        sc.Send(m);
    }
    catch (Exception ex)
    {
        error.Visible = true;
        lblErrorMessage.Text = ex.Message;
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900