简体   繁体   English

在VB.net中发送带有表的Outlook电子邮件

[英]Send Outlook Email with Table in VB.net

I'm using the following code to generate and open an Outlook E-Mail. 我正在使用以下代码来生成并打开Outlook电子邮件。 However I need to be able to insert a table with some variables and my current method only allows for basic text, could anyone suggest a way in which I could integrate a table? 但是我需要能够插入带有一些变量的表,而我当前的方法只允许使用基本文本,有人可以建议一种可以集成表的方法吗?

  Try
       lblStatus.Text = "Opening OutLook Mail, Please Wait..."
        My.Application.DoEvents
        Dim Outl As Object
        Outl = CreateObject("Outlook.Application")
        If Outl IsNot Nothing Then
            Dim omsg As Object
            omsg = Outl.CreateItem(0)
            omsg.body = "Table should go here"
            omsg.To = "*address goes here"
            omsg.subject = SubjectLine
            'set message properties here...'
            omsg.Display(false) 'will display message to user
            lblStatus.Text = "Outlook Mail Template Opened."
            My.Application.DoEvents
        End If
    Catch ex As Exception
        lblStatus.Text = "Opening OutLook Mail | Error Encountered"
           My.Application.DoEvents
        'log error
    End Try

Here's an example of what the table needs to be like: 这是表格需要的示例:

在此处输入图片说明

Obviously there's formatting code used by Outlook, but I don't know how to send that from visual basic into the email. 显然,Outlook使用了格式化代码,但我不知道如何将其从Visual Basic发送到电子邮件中。

First get the DoEvents() out of your code. 首先从代码中获取DoEvents()。 They are not helping anything. 他们没有任何帮助。

As for the table, the simplest way to do it is to build the message body as a HTML string that includes the table. 对于表,最简单的方法是将消息正文构建为包含表的HTML字符串。 Of course, that requires the receiver of the email set to accept HTML. 当然,这要求电子邮件接收方接受HTML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM