从asp.net发送电子邮件

时间:2013-12-03 20:10:05

标签: c# asp.net vb.net smtpclient

当我尝试从我网站的联系我们页面发送电子邮件时,有人可以帮我纠正这个错误

enter image description here

我的代码:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim msg As New MailMessage()
    msg.From = New MailAddress(email.Text)
    msg.[To].Add(New MailAddress("test@milcoxmanor.com"))
    msg.Subject = subject.Text
    msg.Body = Message.Text
    'Try
    '    SmtpMail.SmtpServer = " smtp server name or address "
    '    SmtpMail.Send(msg)
    'Catch ex As HttpException
    '    Response.Write("Error: " + ex.ToString())
    'Catch ex As Exception
    '    Response.Write("Error: " + ex.ToString())
    'End Try
    Dim smtp As New SmtpClient("milcoxmanor.com", 25)
    smtp.Credentials = New NetworkCredential("test@milcoxmanor.com", "12345")
    smtp.Send(msg)


End Sub
Protected Sub ClearFields()
    fname.Text = " "
    lname.Text = " "
    email.Text = " "
    subject.Text = " "
    message.Text = " "
End Sub

结束班

1 个答案:

答案 0 :(得分:1)

根据错误,您可能遗失了:

 Imports System.Net.Mail

位于文件顶部