hi guys, need your help. got this code from this site:

public static void Send(String from, String to, String subject, String messageText).


SmtpMail.Send("mcb@mindcracker.com", "webmaster@mindcracker.com", "Subject", "Message body").

just need your help guys, what's the equivalent code of this in vb express 2010. Thanks. :)

Dani AI

Generated

As found, the sample you linked is C# — in VB you put the mail-sending code inside a Sub (as hinted). The modern, supported way in VB.NET (VB Express 2010 / .NET Framework) is to use System.Net.Mail.MailMessage and System.Net.Mail.SmtpClient. The example below is ready to drop into a form event handler or a module; replace the SMTP host/port and credentials with values from your mail provider.

Imports System.Net
Imports System.Net.Mail

Public Sub SendSimpleMail()
    Dim fromAddress As String = "sender@example.com"
    Dim toAddress As String = "recipient@example.com"
    Dim subject As String = "Test subject"
    Dim body As String = "Test message body"

    Using msg As New MailMessage(fromAddress, toAddress)
        msg.Subject = subject
        msg.Body = body

        Using client As New SmtpClient("smtp.example.com", 587)
            client.EnableSsl = True
            client.Credentials = New NetworkCredential("smtp-username", "smtp-password")
            Try
                client.Send(msg)
            Catch ex As SmtpException
                ' Log or inspect ex.StatusCode and ex.Message for troubleshooting
            End Try
        End Using
    End Using
End Sub

Notes and quick troubleshooting:

  • Add Imports System.Net.Mail at the top of the file.
  • Use the correct SMTP host, port and whether TLS/SSL is required; many providers require authentication.
  • For GUI apps prefer SendAsync and handle SendCompleted to avoid blocking the UI.
  • If sending fails, check credentials, port/firewall, and whether the provider requires an app-specific password or OAuth-based access.

Recommended Answers

All 4 Replies

It should be the same.

hi samuel, thanks for the reply. but the underlie code below it shows, end of statement expected. any thing i'm missing. Thanks.

public static void Send(String from, String to, String subject, String messageText).

hi samuel, thanks for the reply. but the underlie code below it shows, end of statement expected. any thing i'm missing. Thanks.

public static void Send(String from, String to, String subject, String messageText).

This is not C# or C++. This is VB.

you try public sub then the underlined ones, followed by end sub (Your code should between public sub and end sub)

commented: thank you :) +0

thanks for the input, just getting my hands wet in vb.net.

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.