Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emailing

Status
Not open for further replies.

0CODE

Programmer
Feb 8, 2004
63
0
0
CA
Im positive the error is happening because im not setting the server name correcty (obviosly), but I need to know how to retreive the current server or an available one. That or a server name that works. Thanks.

This is the e-mailing code:

Dim objMail As New MailMessage()

SmtpMail.SmtpServer = "Any Server" objMail.From = from
objMail.To = toemail
objMail.Subject = subject
objMail.Body = body

SmtpMail.Send(objMail) ***error happens here


the error i receive
-------------------------------------------------

'Could not access 'CDO.Message' object'

System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040213): The transport failed to connect to the server.




*to try it yourself add a system.web.dll reference and also add at the top of the code "Imports System.Web.Mail"
____________
thanks again
 
Check your Default Mail Client for details of your SMTP. That is providing you are receiving mails. You can use a TCPIP address or a named adress such as webmail@myserver.com

I would also implement a TRY/Catch around the send command

Code:
Private Function SendMail() as Boolean
Dim output As Boolean = True
Try
    myMailServer.Send(myMessage)
Catch
    output = False
Finally
    myMessage = Nothing
End Try
Return output



Sweep
...if it works dont mess with it
 
i did put the try statement but regardless of what i change the stmpserver to it wont work and i get this error:

Could not access 'CDO.Message' object.


i am beggining to think that the smtp server is not the problem but something else. any comments / tips etc would be appreciated - thanks again.
 
although in my first thread on the last line of the error peice there it says it failed to connect to the server so maybe it is a problem with that im setting the smtp server to
 
no idea, how would i find out if i did?
 
I had a similar problem when I attempted to send mail using an SMTP server that required autorization. You could give to following code a shot and see if it helps.

Code:
        With mMail
            .From = tbFrom.Text
            .To = tbTo.Text
            .Subject = tbSubject.Text
            .Body = tbText.Text
            .Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")[/URL] = 1
            .Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusername")[/URL] = "UserId"
            .Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendpassword")[/URL] = "password"

            If (rbPlainText.Checked) Then
                .BodyFormat = MailFormat.Text
            Else
                .BodyFormat = MailFormat.Html
            End If
            If (tbAttachment.Text <> "") Then
                .Attachments.Add(New System.Web.Mail.MailAttachment(tbAttachment.Text))
            End If
        End With

        SmtpMail.SmtpServer = "server.host.com" 'used for this example

        SmtpMail.Send(mMail)
 
wierd i think u may be using a different mail object, since i dont have the "feilds" propery. tell me exactly what your using if you dont mind. thanks
 
do you have VB.NET 2003? im on 2002 and im using the same object as you. and does yours send the message sucessfully? if you take out the authorization code what error do yo get?
 
When I take that code out I get:

An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll

Additional information: Could not access 'CDO.Message' object.
 
k, what version of VB.NET do you have and do you have any other extra's to ur VB.NET?
 
I am using 2003. If you have more questions we should take them off-line. john@cronincomputers.com
 
thanks everyone, but unfortuatly i can't seem to fix the problem, ive changed the server name many times to things that supposedly work - the problem still may be the servername. it could be that i need some other required program or addon that i may need who knows. thanks alot anyway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top