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.MailMessag e '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.Attachment s.Add(New Mail.MailAttachment(CType( attachment s(i), String)))
Next
End If
End If
'Set server
objSMTPServer.SmtpServer = strSMTPServer
'Send message
objSMTPServer.Send(objEmai lMessage)
Catch ex As Exception
WriteErrorLog(ex)
Message("Error sending e-mail." & ex.InnerException.Message( ), Page)
End Try
End Sub
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.MailMessag
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.Attachment
Next
End If
End If
'Set server
objSMTPServer.SmtpServer = strSMTPServer
'Send message
objSMTPServer.Send(objEmai
Catch ex As Exception
WriteErrorLog(ex)
Message("Error sending e-mail." & ex.InnerException.Message(
End Try
End Sub
this migth help:
http://www.emailarchitect.net/WebApp/SMTPCOM/developers/vbnet.asp
good example:
http://www.codeproject.com/vb/net/epsendmail.asp
http://www.emailarchitect.net/WebApp/SMTPCOM/developers/vbnet.asp
good example:
http://www.codeproject.com/vb/net/epsendmail.asp
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
objSMTPServer.Send(objEmai