我有一个用html
和ASP.NET
写的联系表。我想使用<asp:FileUpload>
将文件附加到联系表单生成的电子邮件中,但我根本不知道VB.NET要做什么。我不是一个自然的VB
呃所以它不是我说的语言,我在语言中所做的一切都来自例子。 VB我已经在下面了,谁能告诉我我需要什么VB.NET以及把它放在我已有的代码中? (我在名为Uploads的httpdocs
文件中放置了一个文件夹
提前致谢。
我的代码:
Imports System.Net.Mail
Partial Class Contact_xxxxxxxxxxxxxxx
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim combinedBodyString As String
combinedBodyString = txtDetails.Text & vbCrLf & vbCrLf
combinedBodyString = combinedBodyString & "---------Details-------- " & vbCrLf & vbCrLf
combinedBodyString = combinedBodyString & "Org Name: " & vbTab
combinedBodyString = combinedBodyString & txtOrg.Text & vbCrLf
combinedBodyString = combinedBodyString & "Name: " & vbTab
combinedBodyString = combinedBodyString & txtName.Text & vbCrLf
combinedBodyString = combinedBodyString & "Tel No: " & vbTab
combinedBodyString = combinedBodyString & txtTelephoneNumber.Text & vbCrLf
combinedBodyString = combinedBodyString & "eMail: " & vbTab
combinedBodyString = combinedBodyString & txtEmailAddress.Text & vbCrLf
sendmail(txtEmailAddress.Text, combinedBodyString)
Response.Redirect("~/Enquiry-Complete.aspx")
End Sub
Private Sub sendmail(ByVal from As String, ByVal body As String)
Dim mailservername As String = "relay.hostinguk.net"
Dim message As MailMessage = New MailMessage(from, "xxxx@xxxxxxxx.co.uk", "General Enquiry", body)
Dim mailclient As New SmtpClient
mailclient.Host = mailservername
mailclient.Send(message)
message.Dispose()
End Sub
End Class
答案 0 :(得分:1)
取自...... How to send mail with attachment in asp.net
//Attach file using FileUpload Control and put the file in memory stream
If fileUpload1.HasFile Then
message.Attachments.Add(new Attachment(fileUpload1.PostedFile.InputStream, fileUpload1.FileName))
End If
在mailclient.Host = mailservername
和mailclient.Send(message)
我还建议使用stringbuilder而不是将stings连接在一起。