0

我是 VB 表单的新手,但如果可能的话,我需要一些建议。我想将表单字段作为单行管道分隔的文本文件附件通过电子邮件发送。因此,当您打开发送的电子邮件时,它将附加 *.txt 文件,第一行将如下所示

textbox1_value|textbox2_value|textbox3_value

这是我的电子邮件代码:

Imports System.Net.Mail

Public Class Form1

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        Using message As New MailMessage()
            'set to the from, to and subject fields
            message.From = New MailAddress(TextBox2.Text.ToString())
            message.[To].Add(New MailAddress("steve@steve.com"))
            message.Subject = "Certificate alert"
            'code the message body
            Dim MsgBody As String
            MsgBody = TextBox2.Text.ToString() & vbCr & _
                      TextBox3.Text.ToString() & vbCr & _
                      TextBox4.Text.ToString()
            message.Body = MsgBody
            Dim client As New SmtpClient()
            client.Host = "mailhost"
            client.Send(message)
        End Using
        'display submitted box
        MessageBox.Show("Your Incident has been submitted!", "Congratulations!")
        'close form
        Me.Close()
    End Sub
End Class

任何想法将不胜感激

谢谢!

4

2 回答 2

1

您可以将属于附件中的文本保存到文本文件中,然后:

message.Attachments.Add(New Attachment("filename"))
system.io.file.delete("filename") ' delete the file
于 2013-01-17T16:44:23.140 回答
0

在磁盘上创建文件

Dim filename as String = "C:\Somefile.txt"
My.Computer.FileSystem.WriteAllText(filename, "value1|value2|value3")

然后附加到您的邮件中:

Dim att as New System.Net.Mail.Attachment(filename)
message.Attachments.Add(att)

之后不要忘记删除您的文件

于 2013-01-17T16:40:28.680 回答