Question sending email

lyealain

New member
Joined
Mar 8, 2008
Messages
4
Programming Experience
Beginner
hi.. newbie here..
can you guide me the working code for sending email through vb.net?
i tried to send email through the script below through my localhost , but it is not working ... it said "Send Email Failed.Failure sending mail."
do i have to test that in the server ?

i got this code but don think is working . Please guide
VB.NET:
Imports System.Net.Mail
Partial Class _Default
    Inherits System.Web.UI.Page


    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Dim smtpClient As New SmtpClient()
        Dim message As New MailMessage()

        Try
            Dim fromAddress As New MailAddress("john@yahoo.co.uk", "john")

            smtpClient.Host = "mail.brainEdu.com"

            smtpClient.Port = 25

            message.From = fromAddress

            message.[To].Add("john@yahoo.co.uk")

            message.Subject = "FeedbackTest"

            message.IsBodyHtml = False

            message.Body = "this is a test msg"

            smtpClient.Send(message)

            litStatus.Text = "Email successfully sent."

        Catch ex As Exception

            litStatus.Text = "Send Email Failed." + ex.Message
        End Try
    End Sub
End Class
 
If you set Host to "localhost" it will try to use the Smtp server on local machine, so if you don't have a mail server on your development machine it will not work there.
 
Back
Top