Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Sending an E-Mail VB.NET

Posted on 2006-05-01
4
Medium Priority
?
480 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:RySk8er30
  • 2
4 Comments
 

Author Comment

by:RySk8er30
ID: 16579548
The error is occurring at this line:

objSMTPServer.Send(objEmailMessage)
0
 
LVL 21

Expert Comment

by:oleggold
ID: 16579589
0
 

Author Comment

by:RySk8er30
ID: 16579721
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
 
LVL 44

Accepted Solution

by:
bruintje earned 2000 total points
ID: 16579733
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question