Sending an E-Mail VB.NET

I am trying to send an e-mail in VB.NET.  I am getting the following error message:

Library not registered (Exception from HRESULT: 0X8002801D (TYPE_E_LIBNOTREGISTERED))

Here is my code:

Sub SendEmail(ByVal Page As Page, ByVal strSMTPServer As String, ByVal toAddress As String, ByVal fromAddress As String, ByVal subject As String, ByVal body As String, Optional ByVal bccAddress As String = "", Optional ByVal bodyFormat As Mail.MailFormat = Mail.MailFormat.Text, Optional ByVal attachments As ArrayList = Nothing)

        Try
            Dim objEmailMessage As New System.Web.Mail.MailMessage 'Sets email message object
            Dim objSMTPServer As System.Web.Mail.SmtpMail 'Sets smtp server object
            Dim i As Integer

            'Setup e-mail
            With objEmailMessage
                .To = toAddress
                .Bcc = bccAddress
                .From = fromAddress
                .Subject = subject
                .BodyFormat = bodyFormat
                .Body = body
            End With

            'Add attachments
            If Not attachments Is Nothing Then
                If attachments.Count > 0 Then
                    For i = 0 To attachments.Count - 1
                        objEmailMessage.Attachments.Add(New Mail.MailAttachment(CType(attachments(i), String)))
                    Next
                End If
            End If

            'Set server
            objSMTPServer.SmtpServer = strSMTPServer

            'Send message
            objSMTPServer.Send(objEmailMessage)
        Catch ex As Exception
            WriteErrorLog(ex)
            Message("Error sending e-mail." & ex.InnerException.Message(), Page)
        End Try

    End Sub
RySk8er30Asked:
Who is Participating?
 
bruintjeCommented:
Hi RySk8er30,

you probably did not initialize the server object as you did the mail object

you have
            Dim objEmailMessage As New System.Web.Mail.MailMessage 'Sets email message object
            Dim objSMTPServer As System.Web.Mail.SmtpMail 'Sets smtp server object

you could try
            Dim objEmailMessage As New System.Web.Mail.MailMessage 'Sets email message object
            Dim objSMTPServer As New System.Web.Mail.SmtpMail 'Sets smtp server object


hope this helps a bit
bruintje
0
 
RySk8er30Author Commented:
The error is occurring at this line:

objSMTPServer.Send(objEmailMessage)
0
 
RySk8er30Author Commented:
That didn't help.  The application works on the server fine, so the code is okay.  It looks like there is a problem with a library on my local computer.  Any ideas which library?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.