将pdf作为附件发送到电子邮件中

时间:2010-11-23 07:11:22

标签: c# asp.net winforms email visual-studio-2005

我当前的应用程序在附件中发送.rtf。我希望发送pdf而不是那个。 在我的代码中我应该修改相同的内容吗?

以下是我的代码

        RichTextBox rtbReport = new RichTextBox();   //Creating instance of Richtextbox
        AppResult objResult = null;                  //Object of Class
        frmExaminationReport objReport = new frmExaminationReport(examinationID,   ProviderID, PatientID, examType);                        // Object of Class
        AddressBookDataTable dtAddress = null;
        rtbReport.Rtf = objReport.RTF;               // Entire Result is assigned to Richtext box class
         frmMail objMail = new frmMail();            //Object of Mail Class
         string directoryPath = Application.StartupPath + "\\Temp"; //Creating directory

         string tempFileName = "Report_" + DateTime.Today.Year.ToString() +  DateTime.Today.Month.ToString() + ".rtf";      //Generating Name
            FileStream fsReport = new FileStream(directoryPath + "\\" + tempFileName, FileMode.CreateNew);                            // FileStream
            fsReport.Write(ASCIIEncoding.ASCII.GetBytes(rtbReport.Rtf), 0, rtbReport.Rtf.Length);                         // Writing
            fsReport.Flush();
            fsReport.Close();
            fsReport.Dispose();
            objMail.MailSubject = examType + " Report";   //Mail Subject

如果需要任何输入,请告诉我

1 个答案:

答案 0 :(得分:2)

您的代码不完整或没有意义(仅适用于我?)。 Here is a simple tutorial发送带附件的电子邮件。

如果您使用代码生成PDF文档,请在SO中查看一些related questions

我认为您不能简单地将.rtf更改为.pdf以生成PDF文档。

string tempFileName = examType + "Report_" + DateTime.Today.Year.ToString() +  DateTime.Today.Month.ToString() + ".rtf";