Link to home
Create AccountLog in
Avatar of modeza
modezaFlag for United States of America

asked on

Send email in VB.NET 2005

Hi experts.. I hope you guys can help me with this issue.. Thanks in advance.

In the event click of my command button.. I'd like to send an email... I tried this:

Imports System.Net.Mail.MailMessage   (this line I put it  in the first row)

Protected Sub btnsend_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsend.Click
Try
            Dim emailTitle As String = "My Email Title"
            Dim emailMessage As Net.Mail.MailMessage
            Dim body As String = "This will appear in the body of my email"

            emailMessage = New Net.Mail.MailMessage "from@emailaddress", "to@emailaddress", "Test", "TEST2")
            MsgBox("You request was sent, thanks")
            Dim mailClient As New Net.Mail.SmtpClient("Here goes the IP server", 25)

        Catch ex As Exception

        End Try
End Sub



Am I doing something wrong?? Could you tell me what is the best way to send a confirmation mail.. in VB.NET 2005.. please...

Thanks :)
Avatar of VBRocks
VBRocks
Flag of United States of America image

Here's a little sub you can use:

        Public Sub SendEmail(ByVal Sender As String, ByVal Recipient As String, _
            ByVal Subject As String, ByVal Body As String)

            Dim smtp As New Net.Mail.SmtpClient("1.30.75.75")

            'separate recipients by comma
            smtp.Send(Sender, Recipient.Replace(";", ","), Subject, Body)

            smtp = Nothing

        End Sub
Here's your code, you just needed to add a call to the Send method:

            Dim emailTitle As String = "My Email Title"
            Dim emailMessage As Net.Mail.MailMessage
            Dim body As String = "This will appear in the body of my email"

            emailMessage = New Net.Mail.MailMessage _
                     ("from@emailaddress", "to@emailaddress", "Test", "TEST2")

            Dim mailClient As New Net.Mail.SmtpClient(IPAddress)
            mailClient.Send(emailMessage)

            MsgBox("You request was sent, thanks")

Avatar of modeza

ASKER

It doesnt send the email...

something else.. that can help ???

thanks
Well, what kind of problem are you having?

Make sure you change "IPAddress" to the name of your email server, or the IP address.



ASKER CERTIFIED SOLUTION
Avatar of vadim63
vadim63
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Éric Moreau
Hi

Just check this, you can get complete idea about how to send the mail.


http://www3.sendthisfile.com/d.jsp?t=JchZ4sux2LfyobQ6WEng8OXS
Avatar of modeza

ASKER

Thank you   vadim63   ITS WORKING :)  

You're awesome

Glad to help.
Avatar of DataOcean
DataOcean

What Happen If We Have Exchange server