Hi freinds
I want to send an email using VB.NET2005.
Can any one help me in it any :icon_redface:
code??????

Dani AI

Generated

Practical, durable approach for sending email from VB.NET 2005 (question from ). The .NET Framework includes System.Net.Mail (MailMessage + SmtpClient), which avoids COM components. 's CDO and MAPI examples are valid where those components exist, and is right to point toward SMTP — the snippet below is a compact, production-aware example and a minimal web.config entry.

Imports System.Net
Imports System.Net.Mail

Public Sub SendMail(toAddress As String)
    Using msg As New MailMessage("sender@example.com", toAddress)
        msg.Subject = "Subject here"
        msg.Body = "Plain text body"
        msg.IsBodyHtml = False

        Using smtp As New SmtpClient("smtp.example.com", 587)
            smtp.Credentials = New NetworkCredential("smtpuser", "smtppassword")
            smtp.EnableSsl = True
            smtp.Send(msg)
        End Using
    End Using
End Sub
<system.net>
  <mailSettings>
    <smtp from="sender@example.com">
      <network host="smtp.example.com" port="587" userName="smtpuser" password="smtppassword" enableSsl="true" />
    </smtp>
  </mailSettings>
</system.net>

Troubleshooting and production notes:

  • Authentication errors: verify credentials and provider requirements (many providers require app-specific passwords or OAuth2 when 2FA is enabled).
  • Connection refused/timeouts: confirm host and port (25/587/465), check firewall/ISP blocking.
  • TLS/SSL problems: try port 587 with EnableSsl=true (STARTTLS) or 465 depending on server.
  • Relaying/From address rejected: SMTP server may restrict the From address to the authenticated account.
  • Resource cleanup: always Dispose MailMessage/Attachments (Using blocks) to avoid file locks.
  • For web apps: place credentials in config or a secure store and queue/execute large sends off the request thread.

Note: SmtpClient is appropriate for .NET Framework (VB.NET 2005). Projects targeted at newer runtimes typically use modern libraries (for example MailKit) and provider-specific APIs for OAuth2.

Recommended Answers

All 4 Replies

Try using Microsoft's CDO control. Finding it may be a head ache since there are a bunch of different versions. I think that I was using 6.5 when I wrote this;

Private Sub SendMail(ByVal sEmail As String)
        'this procedure recieves an email address and sends a message.
        'Dim objCDO As New CDO.Message
        Dim objSendMail As New CDO.Message
        Dim strEmailAddress As String

        Try
            strEmailAddress = sEmail
            With objSendMail
                .From = "emailaddress@somewhere.com"
                .To = RTrim(strEmailAddress)
                '.CC = "ccemail@somewhere.com"
                .Subject = "Your Subject Here"
                .TextBody = "Put your message here"
                .HTMLBody = "<H3>For HTML Messages</H3>" & _
                            "<P>Format in HTML just put everything between quotes</P>"
                .Send()
            End With
        Catch ex As Exception
            'do your error handling here
        Finally
            objSendMail = Nothing
        End Try

End Sub

CDO.dll came with Outlook Pro prior to the 2007 version (I don't know if it ships with 2007). If you don't have it you should be able to find it by searching http://msdn.microsoft.com.

Another way is to add a MAPI control to your project. I've only did this in one project but I hear that it is best with VB .NET 2005. This is what I wrote.

Private Sub sendMail(ByVal FName As String, ByVal lName As String, ByVal eMail As String)
        'sends the email
        Try
            'Open up a MAPI session
            Me.mapiSession.SignOn()

            'Point the MAPI messages control to the open MAPI session
            Me.mapiMessage.SessionID = Me.mapiSession.SessionID

            'Start a new message
            Me.mapiMessage.Compose()

            With Me.mapiMessage
                .MsgSubject = "Your Subject"
                .MsgReceiptRequested = True
                .MsgNoteText = "This is the message."
                .RecipType = 1
                .RecipAddress = eMail
                .Action = 13
                .Send(False)
            End With

            'sign off of the session
            Me.mapiSession.SignOff()

            'increase the mail count
            Me.mintSent += 1

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

recently i was faced a problem to update, insert and delete the data from the table by using vb.net code, can u help me to solve the problem.

Teopohkuang; I can help but can you create a new thread with your question, include as much detail about your problem as you can describe, so that others with similar problems can more easily find it?

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.