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
{
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);
}
}