none
send crystall report mail error? RRS feed

  • Question

  • private void sendmail_Click(object sender, EventArgs e)
            {
                try
                {
                    ExportOptions CrExportOptions ;
                    DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                    PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                    CrDiskFileDestinationOptions.DiskFileName = pdfFile;
                    CrExportOptions = cryRpt.ExportOptions;
                    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                    CrExportOptions.FormatOptions = CrFormatTypeOptions;
                    cryRpt.Export();

                    sendmail1();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            private void sendmail1()
            {
                try {
                    SmtpMail.SmtpServer.Insert(0, "smtp2go.com");
                    MailMessage Msg = new MailMessage();
                    Msg.To = "mathking_cse@yahoo.com";
                    Msg.From = "shamsuddinarefin@gmail.com";
                    Msg.Subject = "Crystal Report Attachment ";
                    Msg.Body = "Crystal Report Attachment ";
                    Msg.Attachments.Add(new MailAttachment(pdfFile));
                    System.Web.Mail.SmtpMail.Send(Msg);
                }
                catch (Exception ex) {
                    MessageBox.Show (ex.ToString());
                }         
            }

    when i run the progrm .give some warning?

    Warning    1    'System.Web.Mail.SmtpMail' is obsolete: '"The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202"'    C:\Users\arefin\Documents\Visual Studio 2010\Projects\crystalPractics2\crystalPractics2\Form1.cs    117    17    crystalPractics2

    Warning    2    'System.Web.Mail.SmtpMail' is obsolete: '"The recommended alternative is System.Net.Mail.SmtpClient. http://go.microsoft.com/fwlink/?linkid=14202"'    C:\Users\arefin\Documents\Visual Studio 2010\Projects\crystalPractics2\crystalPractics2\Form1.cs    124    17    crystalPractics2

    Sunday, April 1, 2012 4:21 PM

All replies

  • Please use the following code, your code is only supported before .Net 2.0

    using System.Net.Mail;
    
    static void SendMail()
    {
    MailMessage msg = new MailMessage();
    
    msg.To.Add(“toaddress1@whatever.com,toaddress2@blah.com”);
    msg.From = new MailAddress(“fromaddress@whatever.com”);;
    msg.Subject = “My Subject”;
    msg.Body = “My Body”;
    
    msg.IsBodyHtml = true;
    
    SmtpClient smtpClient = new SmtpClient(“yourmailserveraddressorip”);
    
    smtpClient.Send(msg);
    
    }


    Regards, Nighting Liu

    Sunday, April 1, 2012 4:37 PM