[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1732
  • Last Modified:

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 :)
0
modeza
Asked:
modeza
  • 3
  • 2
  • 2
  • +3
1 Solution
 
VBRocksCommented:
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
0
 
VBRocksCommented:
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")

0
 
modezaAuthor Commented:
It doesnt send the email...

something else.. that can help ???

thanks
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
VBRocksCommented:
Well, what kind of problem are you having?

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



0
 
vadim63Commented:
Try this:


Imports System.Net.Mail

Public Class Form1

    Private Sub SendMail()
        Dim Client As New SmtpClient("mail.yourcompany.com")
        Dim m As New MailMessage()
        m.From = New MailAddress("support@yourcompany.com")
        m.To.Add(New MailAddress("admin@yourcompany.com"))
        m.Subject = "Test subject"
        Client.UseDefaultCredentials = False
        Client.Credentials = New Net.NetworkCredential("support", "12345")
        m.Body = "test body"
        m.Priority = MailPriority.High
        Client.Send(m)
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendMail()
    End Sub
        End Class
0
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
srinivasbnCommented:
Hi

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


http://www3.sendthisfile.com/d.jsp?t=JchZ4sux2LfyobQ6WEng8OXS
0
 
modezaAuthor Commented:
Thank you   vadim63   ITS WORKING :)  

You're awesome

0
 
vadim63Commented:
Glad to help.
0
 
DataOceanCommented:
What Happen If We Have Exchange server
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now