Vb.net program that sends email? Can we do that?
A:
Hi , Send email in vb.net
Or
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("[email protected]", "password")
SmtpServer.Port = 587
SmtpServer.Host = "smtp.gmail.com"
mail.From = New MailAddress("[email protected]")
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
Pandiya Chendur
2009-12-15 03:42:18
Looks about right, although I would suggest `Using mail As New MailMessage()` since MailMessage implements IDisposable
MarkJ
2009-12-15 12:18:48
Also, the code instantiates a new MailMessage twice.
Meta-Knight
2009-12-15 14:30:13
this is the typical coding-in-the-dark style of programming- banging through exceptions until it "works". generally youll see every method start with try and end with catching the base exception. we had one developer who would do. catch ex as exception... response.write("<script>alert('" </script>") in every method. users loved seeing those. as an added bonus, if there was a single quote in the exception message, there would be a js error and the page wouldnt execute correctly
Shawn Simon
2009-12-15 14:37:50