【问题标题】:VB.net Crystal report export to html and send as html mail body using outlookVB.net Crystal 报表导出为 html 并使用 Outlook 作为 html 邮件正文发送
【发布时间】:2020-01-29 14:26:49
【问题描述】:

我正在尝试使用 Outlook 应用程序将水晶报告的内容作为电子邮件正文发送。 这是我在 VB.net 中的代码

Imports outlook = Microsoft.Office.Interop.Outlook
Dim a As String = something.ConnectionString
            Dim cryRpt As ReportDocument
            Dim username As String = a.Split("=")(3).Split(";")(0) 'get username
            Dim password As String = a.Split("=")(4).Split(";")(0) 'get password
            cryRpt = New ReportDocument()
            Dim Path As String = Application.StartupPath
            Dim svPath As String = Application.StartupPath & "\PDF"
            If Not Directory.Exists(svPath) Then
                Directory.CreateDirectory(svPath)
            End If
            cryRpt.Load(Path & "\Reports\dr.rpt")
            CrystalReportViewer1.ReportSource = cryRpt
            cryRpt.SetDatabaseLogon(username, password)
            CrystalReportViewer1.Refresh()
            Dim myExportOptions As ExportOptions
            myExportOptions = cryRpt.ExportOptions
            myExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
            myExportOptions.ExportFormatType = ExportFormatType.HTML40 'i tried HTML32 also
            Dim html40FormatOptions As HTMLFormatOptions = New HTMLFormatOptions()
            html40FormatOptions.HTMLBaseFolderName = svPath
            html40FormatOptions.HTMLFileName = "dr.htm"
            html40FormatOptions.HTMLEnableSeparatedPages = False
            html40FormatOptions.HTMLHasPageNavigator = False
            html40FormatOptions.UsePageRange = False
            myExportOptions.FormatOptions = html40FormatOptions
            cryRpt.Export()

    Try
                Dim oApp As outlook.Application
                oApp = New outlook.Application

                Dim oMsg As outlook.MailItem
                oMsg = oApp.CreateItem(outlook.OlItemType.olMailItem)

                oMsg.Subject = txtSubject.Text
                oMsg.BodyFormat = outlook.OlBodyFormat.olFormatHTML
                 oMsg.HTMLBody = ""

                oMsg.HTMLBody = getFileAsString(svPath & "\PoPrt\QuotPrt.html")

                oMsg.To = txtEmailId.Text
                Dim ccArray As New List(Of String)({txtCC1.Text, txtCC2.Text, txtCC3.Text})
                Dim cclis As String = String.Join(",", ccArray.Where(Function(ss) Not String.IsNullOrEmpty(ss)))
                oMsg.CC = cclis
                oMsg.Display(True)
            Catch ex As Exception
                MsgBox("Something went wrong", vbExclamation)
            End Try
            SvFormPanel3.Visible = False

功能

Private Function getFileAsString(ByVal file As String) As String
        Dim reader As System.IO.FileStream
        Try
            reader = New System.IO.FileStream(file, IO.FileMode.Open)
        Catch e As Exception
            MsgBox("Something went wrong. " + e.Message, vbInformation)
        End Try

        Dim resultString As String = ""
        Dim b(1024) As Byte
        Dim temp As UTF8Encoding = New UTF8Encoding(True)

        Do While reader.Read(b, 0, b.Length) > 0
            resultString = resultString & temp.GetString(b)
            Array.Clear(b, 0, b.Length)
        Loop

        reader.Close()
        Return resultString
    End Function

报告将以 html 格式导出到指定位置。当我们手动打开该 html 文件时,它会完美地显示边界线和所有内容。 但是当它被添加为outlook应用程序的html主体时,格式就会消失,看起来很分散。 谁能帮忙

【问题讨论】:

    标签: vb.net outlook crystal-reports export-to-html


    【解决方案1】:

    你试过了吗?

    打开outlook,转到,文件>选项>邮件

    转到 MessageFormat 部分并取消选中“通过删除格式来减小消息大小...”

    【讨论】:

    • 是的,我也试过了。我知道问题出在生成的 CSS 上。当我尝试 myintervals.com/emogrifier.php 时,它工作正常。我们是否有任何类似的解决方案来使我们的 html 和 css 邮件客户端友好
    【解决方案2】:

    我已经解决了这个问题,将其导出为 PDF,然后转换为图像并嵌入到电子邮件正文中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-08
      • 2020-11-07
      • 2018-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-21
      相关资源
      最近更新 更多