如何将生成的水晶报告发送给邮件收件人 [英] How to send a crystal report generated to a mail recipient

查看:123
本文介绍了如何将生成的水晶报告发送给邮件收件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



i有一个项目正在进行中,所有我想做的我创建了一个水晶报告,但我想做的是,我想要水晶报告创建为作为pdf邮件发送给收件人而不必查看它,它应该只是一键发送邮件。以下是我的代码



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 = "";

}





我的尝试:



我不知道如何去做但这里是我的发送邮件的代码,工作正常,但我怎么能将水晶报告添加到邮件作为附件。



这是我发送电子邮件的一个例子,这个工作正常



private void Button1_Click(对象发送者, EventArgs e)

{



if(txtEmail.Text ==)

{

MessageBox.Show(输入您的电子邮件,错误,MessageBoxButtons.OK,MessageBoxIcon.Error);

txtEmail.Focus();

返回;

}

尝试

{

Cursor = Cursors.WaitCursor;

timer1.Enabled = true;

DataSet ds = new DataSet();

SqlConn ection 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)

{

字符串收件人;

recipient = txtEmail.Text;

MailMessage Msg = new MailMessage( );

//发件人电子邮件地址。

Msg.From =新邮件地址(jinny@gmail.com);

//收件人电子邮件地址。

Msg.To.Add(收件人);

Msg.Subject =您的密码详情;

Msg.Body =你的密码是:+ Convert.ToString(ds.Tables [0] .Rows [0] [Password])+;

Msg.IsBodyHtml = true ;

//您的远程SMTP服务器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((密码成功发送+(\\\\ n+请检查您的邮件)),谢谢,MessageBoxButtons.OK,MessageBoxIcon.Information); this.Hide();

st1 = lblUser.Text;

st2 =密码被恢复;

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

}

}



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

推荐答案

你无法添加CR向电子邮件报告并发送。但是,您可以将报告导出为PDF并将其作为附件发送。



另一种选择是向收件人发送链接到将生成报告,只要您的网站支持使用URL中的某种数据呈现CR报告,以告知该报告以及该特定用户所需的任何其他信息。
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.


嗨!!!



以下链接将向您解释如何将Crystal Report转换为PDF

水晶报告到pdf



for使用以下方法发送带附件的电子邮件



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

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


这篇关于如何将生成的水晶报告发送给邮件收件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆