CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2001
    Posts
    8

    sending email with vb

    Hi.
    i tried to send an email with vb, but failed.
    i used the following code:

    Private Sub Command1_Click()
    Dim myMail
    Set myMail = CreateObject("CDONTS.NewMail")
    myMail.From = "[email protected]"
    myMail.To = "[email protected]"
    myMail.Subject = "Sample Message"
    myMail.Body = "This is a sample message."
    myMail.AttachFile "c:\sample.txt"
    myMail.Send
    Set myMail = Nothing
    End Sub

    I always get an error message like
    Active-x component cannot create objects

    Can anyone please help me?

    Thank you

    PS: Can anyone send me the sample programm "vbmail.vbp". It wasnt included in my version of vb.





  2. #2

    Re: sending email with vb

    have U installed option pack 4?

    <center>
    <HR width=80%>
    <img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
    </center>

  3. #3
    Join Date
    Aug 2001
    Posts
    26

    Re: sending email with vb

    Hi,
    Creating objects requires that the object'sclass be registered in the systemregistry and that any associateddynamic-link libraries (DLL) be available. This error has the following causes and solutions:

    The class isn't registered. For example, the system registry has no mention of the class, or the class is mentioned, but specifies either a file of the wrong type or a file that can't be found.
    If possible, try to start the object's application. If the registry information is out of date or wrong, the application should check the registry and correct the information. If starting the application doesn't fix the problem, rerun the application's setup program.

    A DLL required by the object can't be used, either because it can't be found, or it was found but was corrupted.
    Make sure all associated DLLs are available. For example, the Data Access Object (DAO) requires supporting DLLs that vary among platforms. You may have to rerun the setup program for such an object if that is what is causing this error.

    The object is available on the machine, but it is a licensedAutomation object, and can't verify the availability of the license necessary to instantiate it.


  4. #4
    Join Date
    Aug 2001
    Location
    New York, USA
    Posts
    169

    Re: sending email with vb

    This sample uses MAPI. Make sure you have Outlook installed. I also posted a "SMTP/POP3" sample for your other question: "Email without MAPI" if this is not what you needed.


    'Create MAPI Session
    set objsession = CreateObject("MAPI.session")
    'Login using the default username
    objSession.Logon "", "", false, false, 0
    'Create message object
    set objNewMessage = objsession.Outbox.Messages.Add
    'Create recipient object
    set objRecipient = objNewMessage.Recipients.Add
    'Create attachment object
    set objAttachment = objNewMessage.Attachments.Add

    objRecipient.Name = [email protected]
    objNewMessage.Subject = "Test Subject"
    objNewMessage.Text = "Test Message"
    objAttachment.Source = FileName & FileExtension
    objAttachment.Name = FileName & FileExtension
    objAttachment = Path & Filenumber & FileExtension
    objRecipient.Resolve
    objNewMessage.Update
    objNewMessage.Send
    objSession.Logoff




    [email protected]

  5. #5
    Join Date
    May 2000
    Location
    south korea-seoul
    Posts
    13

    Re: sending email with vb

    use the following code in the module

    Option Explicit
    Public Const EMAIL = "[email protected]"
    Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    Public Const SW_SHOWNORMAL = 1
    Public Sub sendemail()
    Dim Success As Long
    Success = ShellExecute(0&, vbNullString, "mailto:" & EMAIL, vbNullString, "C:\", SW_SHOWNORMAL)
    End Sub


    and use this code in the application form

    onclick event --->
    sendmail


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured