【发布时间】:2013-09-05 01:43:08
【问题描述】:
我知道这个问题以前出现过,但是答案并没有直接回答我的问题,这几天我也在网上搜索过。
问题是,我有一个发送到电子邮件的asp.net VB表单。但是,它出现错误“参数'地址'不能是空字符串。参数名称:地址” 当我点击提交时。但奇怪的是,它实际上仍然发送了包含所有相关信息的电子邮件。
任何人对为什么它给出错误但仍然发送有任何想法? 我觉得这很简单,但它让我很头疼!如果您需要其他代码 sn-ps,请告诉我。
代码背后:
Imports System.IO
Imports System.Net
Imports System.Net.Mail
Partial Class _default
Inherits System.Web.UI.Page
Protected Sub submitButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles submitButton.Click
'send new confirmation email
Try
'create the email message
Dim EmailMsg As New MailMessage()
'set the address and subject
EmailMsg.From = New MailAddress(emailTextBox.Text.ToString)
EmailMsg.To.Add("myemailaddress")
EmailMsg.Subject = "Website enquiry from " + firstnameTextBox.Text.ToString
'set the content
EmailMsg.Body = "First Name: " + firstnameTextBox.Text.ToString + "<br>" +
"Last Name: " + lastnameTextBox.Text.ToString + "<br>" +
"Reply to: " + emailTextBox.Text.ToString + "<br>" +
"Ph No.: " + phoneTextBox.Text.ToString + "<br>" +
"Dropdown value:" + DropDownList1.SelectedValue + "<br>" +
"Website Address: " + webAddressTextBox.Text.ToString + "<br>" +
"Other option: " + otherTextBox.Text.ToString
EmailMsg.IsBodyHtml = True
'send the message
Dim smtp As New SmtpClient()
smtp.Send(EmailMsg) 'uses web.config settings
'if successful clear form and show success message
firstnameTextBox.Text = String.Empty
lastnameTextBox.Text = String.Empty
emailTextBox.Text = String.Empty
phoneTextBox.Text = String.Empty
DropDownList1.SelectedValue = Val("0")
webAddressTextBox.Text = String.Empty
otherTextBox.Text = String.Empty
lblMessage.Text = "Message sent successfully!"
Catch ex As Exception
'show error message if unsuccessful
lblMessage.Text = ex.Message
End Try
End Sub
End Class
Web.config:
<configuration>
<system.net>
<mailSettings>
<smtp>
<network host="server"
port="25"
userName="myemailaddress"
password="mypassword"/>
</smtp>
</mailSettings>
提前致谢
【问题讨论】:
标签: asp.net vb.net forms email