0

我意识到这个问题之前已经出现过,但答案并没有直接回答我的问题,最近几天我也在网上搜索过。

问题是,我有一个发送到电子邮件的 asp.net VB 表单。但是,当我单击提交时,它出现错误“参数'地址'不能是空字符串。参数名称:地址” 。但奇怪的是,它实际上仍然发送包含所有相关信息的电子邮件。

任何人对为什么它给出错误但仍然发送有任何想法?我觉得这很简单,但它让我很头疼!如果您需要其他代码片段,请告诉我。

代码背后:

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

网络配置:

<configuration>
<system.net>
<mailSettings>
  <smtp>
    <network host="server" 
             port="25"
             userName="myemailaddress"
             password="mypassword"/>
  </smtp>
</mailSettings>

提前致谢

4

2 回答 2

2

尝试使用

EmailMsg.To.Add(New MailAddress("myemailaddress"))

我认为您需要将 MailAddress 对象添加到您的收件人列表中。我在我的代码中做,我没有得到任何错误。

于 2013-09-02T02:57:50.260 回答
-1

本地 DEV 和生产服务器之间的 .net 不匹配

于 2016-02-03T16:41:55.857 回答