how to email using vb? how to find SMTP?

Recommended Answers

All 3 Replies

What do you have so far?

What exactly do you need?

Be more specific so we can help you get a solution.:)

how to email using vb? how to find SMTP?

I use the following code in my simple app:

Private Sub SendEmailButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendEmailButton.Click
        'create the mail message
        Dim mail As New Net.Mail.MailMessage()

        Try
            'set the addresses
            mail.From = New Net.Mail.MailAddress(FromTextBox.Text)
            mail.To.Add(ToTextBox.Text)

            'set the content
            mail.Subject = SubjectTextBox.Text
            mail.Body = MessageTextBox.Text

            'send the message
            Dim smtp As New Net.Mail.SmtpClient(SMTPTextBox.Text)

            'to authenticate we set the username and password properites on the SmtpClient
            smtp.Credentials = New Net.NetworkCredential(UserNameTextBox.Text, PasswordTextBox.Text)
            smtp.Send(mail)

        Catch ex As Exception
            Beep()
            Dim msg2 As String
            Dim title2 As String
            Dim style2 As MsgBoxStyle
            Dim response2 As MsgBoxResult

            msg2 = "There has been an error sending the email.  Please check your settings and try sending the email again."   ' Define message.
            style2 = MsgBoxStyle.OkOnly Or MsgBoxStyle.Critical
            title2 = "Email Error"   ' Define title.
            ' Display message.
            response2 = MsgBox(msg2, style2, title2)
            If response2 = MsgBoxResult.Ok Then      ' User chose Ok.
                Exit Sub
            Else
                'Do nothing
            End If
        End Try
End Sub

The use just has to supply the SMTP Address, and its corresponding username and password.

@exception, please mark this thread as solved if you have managed to get a solution, found at the bottom of this page, thanks.:)

It has been open for some time now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.