VB.net receiving and sending a email

點閱: 386

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("trowbridge97@gmail.com", "qwerty1205")
        SmtpServer.Port = 587
        SmtpServer.Host = "smtp.gmail.com"
        mail = New MailMessage()
        mail.From = New MailAddress("trowbridge97@gmail.com")
        mail.To.Add("trowbridge97@gmail.com")
        mail.Subject = "Alarm"
        mail.Body = "Some one is in your room"
        SmtpServer.Send(mail)
        MsgBox("mail send")
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *