2013-01-17 43 views
0

我是VB表單的新手,但需要一些建議,如果這是可能的。我想通過電子郵件將表單字段作爲單行管道分隔文本文件附件。所以,當您打開發送的電子郵件將有* .txt文件並連接1號線看起來像這樣VB表單作爲附件在文本文件中發送表單域的電子郵件

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("[email protected]")) 
      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 

任何想法將不勝讚賞

謝謝!

回答

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) 

不要忘記刪除你的文件之後

+0

我可以得到的代碼發送後自動刪除它自動? – user1802739

+0

只是谷歌它 - 或鍵入'My.Computer.FileSystem.',看看接下來會發生什麼 –

+0

My.Computer.FileSystem.WriteAllText(filename,「value1 | value2 | value3」) – user1802739

1

您可以保存屬於文本在附件中的文本文件中,則:

message.Attachments.Add(New Attachment("filename")) 
system.io.file.delete("filename") ' delete the file 
相關問題