发送电子邮件的Vb.net程序?

发送电子邮件的Vb.net程序?,vb.net,Vb.net,发送电子邮件的Vb.net程序? 我们能做到吗 或 看起来不错,不过我建议使用mail As New MailMessage(),因为MailMessage实现了IDisposablet这是一种典型的黑暗编程风格的编码——不断地处理异常,直到它“工作”。通常,您会看到每个方法都以try开始,以捕获基本异常结束。我们有一个开发人员可以这样做。捕获ex作为例外。。。在每个方法中写入(“alert(“&ex.tostring&“);”)。用户喜欢看到这些。另外,如果异常消息中只有一个引号,则会出现j

发送电子邮件的Vb.net程序? 我们能做到吗


看起来不错,不过我建议
使用mail As New MailMessage()
,因为MailMessage实现了IDisposablet这是一种典型的黑暗编程风格的编码——不断地处理异常,直到它“工作”。通常,您会看到每个方法都以try开始,以捕获基本异常结束。我们有一个开发人员可以这样做。捕获ex作为例外。。。在每个方法中写入(“alert(“&ex.tostring&“);”)。用户喜欢看到这些。另外,如果异常消息中只有一个引号,则会出现js错误,页面将无法正确执行
Imports System.Net.Mail
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
      ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New _
              Net.NetworkCredential("username@gmail.com", "password")
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            mail.From = New MailAddress("YOURusername@gmail.com")
            mail.To.Add("TOADDRESS")
            mail.Subject = "Test Mail"
            mail.Body = "This is for testing SMTP mail from GMAIL"
            SmtpServer.Send(mail)
            MsgBox("mail send")
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub
End Class