我在vb.net上发了电子邮件表单但是我需要发送一个使用html格式的邮件,我发的也可以,但是当我收到邮件时,用文本框写的值不是邮件。这有什么问题?
Imports System
Imports System.Net.Mail
Imports System.Net
Imports System.IO
Imports System.Configuration
Partial Class Form
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
Protected Sub submit_button_Click(sender As Object, e As EventArgs) Handles submit_button.Click
SendHTMLMail()
End Sub
' Method Which is used to Get HTML File and replace HTML File values with dynamic values and send mail
Public Sub SendHTMLMail()
Dim reader As New StreamReader(Server.MapPath("html.html"))
Dim readFile As String = reader.ReadToEnd()
Dim myString As String = ""
myString = readFile
myString = myString.Replace("$$Company_Name$$", "Company_Name")
myString = myString.Replace("$$Contact_Person_Name$$", "Txt_ContactPerson.Text")
myString = myString.Replace("$$Contact_Person_Mobile_No$$", "Txt_Contact_No.Text")
myString = myString.Replace("$$Telephone_No$$", "Txt_TelNo.Text")
myString = myString.Replace("$$Email_Id$$", "Txt_Email.Text")
myString = myString.Replace("$$Registered_Address$$", "Txt_Address.Text")
myString = myString.Replace("$$Year_Of_Commencement_Of_Business$$", "Txt_CommenceYear.Text")
myString = myString.Replace("$$Income_TAX_PAN_No$$", "Txt_IncomeTax.Text")
myString = myString.Replace("$$CST_No$$", "Txt_CSTNo.Text")
myString = myString.Replace("$$VAT_TIN_No$$", "Txt_VatNo.Text")
myString = myString.Replace("$$Type_Of_Business_Entity$$", "RadioButtonList1.SelectedValue.ToString")
myString = myString.Replace("$$Full_Details$$", "")
myString = myString.Replace("$$Business_History$$", "Txt_BusinessHistory.Text")
myString = myString.Replace("$$No_Of_Employees$$", "Txt_NoOfEmployees.Text ")
myString = myString.Replace("$$Annual_Turnover$$", "")
myString = myString.Replace("$$References$$", "")
Dim MyMailMessage As New MailMessage()
MyMailMessage.From = New MailAddress("test@eternalbs.com", "Eternal")
MyMailMessage.To.Add("test@eternalbs.com")
MyMailMessage.Subject = "Eternal"
MyMailMessage.Body = myString.ToString()
MyMailMessage.IsBodyHtml = True
' Dim SMTPServer As New SmtpClient("smtp.gmail.com")
Dim SMTPServer As New SmtpClient()
SMTPServer.Host = "208.91.198.227"
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential("test@eternalbs.com", "admin123")
'SMTPServer.EnableSsl = True
Try
SMTPServer.Send(MyMailMessage)
Response.Write("Successfull")
Catch ex As SmtpException
Response.Write(ex)
End Try
End Sub
End Class
答案 0 :(得分:0)
要接收用户已插入的任何文本框的值,该值不得为双引号。在SendHTMLmail()函数中,您希望捕获文本框值的第二个参数,您只需删除双引号逗号
myString = myString.Replace("$$Contact_Person_Name$$", Txt_ContactPerson.Text)
对于要捕获其值的每个文本框,请尝试此操作。希望它有所帮助。