Link to home
Start Free TrialLog in
Avatar of RySk8er30
RySk8er30

asked on

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
Avatar of RySk8er30
RySk8er30

ASKER

The error is occurring at this line:

objSMTPServer.Send(objEmailMessage)
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?
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial