how to email using vb? how to find SMTP?

Dani AI

Generated

As showed, the app needs an SMTP host and credentials. If you do not know what to put in the SMTP field, check the email account settings in your mail client (Outlook/Thunderbird), or the provider support pages. Common examples and ports are documented by providers (Gmail settings are here: ). For company mail, ask the mail admin for the relay host, port and any IP allowlist requirements.

Ports and security matter. Port 587 (STARTTLS) is the modern standard; port 465 is legacy SSL and port 25 is often blocked by ISPs. Many servers require TLS and either an app-specific password or OAuth2 instead of plain username/password (Google and Microsoft have moved away from basic auth). If you see errors like "requires a secure connection or the client was not authenticated", check port, TLS, and whether the account requires an app password or OAuth.

If you are writing new code, be aware that the historical SmtpClient approach still works on .NET Framework but is not recommended for new development on modern .NET. Consider MailKit for SMTP or provider APIs (Microsoft Graph for Office 365, Gmail API) if you need OAuth, reliability, or advanced features. See MailKit on GitHub: MailKit and Microsoft Graph send mail docs: Send mail with Microsoft Graph.

For development and troubleshooting use a local/testing SMTP sink (smtp4dev or Mailtrap) so you do not spam real inboxes. If mail fails: check firewall/port blocking, match the From address policy required by the SMTP server, confirm 2FA/app passwords, and review exact exception messages for auth vs TLS vs connection issues. Note that previously asked to mark the thread solved when resolved.

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.

, 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.