Results 1 to 5 of 5

Thread: Create an email, works SOME of the time. See code inside

  1. #1

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747

    Create an email, works SOME of the time. See code inside

    Code:
    Private Function Email_Error(ByVal ToEmailAddresses As String, _
                                 Optional CCEmailAddresses As String = "", _
                                 Optional Subject As String = " ", _
                                 Optional MessageBody As String = " ")
    'When a run-time error occurs, this routine fires off an e-mail to the author
                         
    On Error GoTo ErrHandler
    
        Const CONST_EMAIL_COMMAND = "MailTo:{ToEmailAddresses}&CC={CCEmailAddresses}&Subject={Subject}&Body={MessageBody}"
        
        Dim rc As Variant
        Dim sCommand As String
    
        If ToEmailAddresses = "" Then
            MsgBox "No e-mail address has been set up for the developer. Please enter this in the To: line of the e-mail."
        End If
        sCommand = "MailTo:" & ToEmailAddresses
        If CCEmailAddresses <> "" Then sCommand = sCommand & "?CC=" & CCEmailAddresses
        If Subject <> "" Then sCommand = sCommand & "?Subject=" & Subject
        If MessageBody <> "" Then
            'Ampersands, spaces, and line breaks need to be a special character in our 'mailto:' string
            'NOTE: I could not find anything to handle [Tab] characters...so I just use five spaces to
            'represent a [Tab] character. I know you can do better, though! ;-)
            MessageBody = Replace(MessageBody, vbTab, Space(5))
            MessageBody = Replace(MessageBody, " ", "%20")
            MessageBody = Replace(MessageBody, "&", "%26")
            MessageBody = Replace(MessageBody, vbCrLf, "%0D%0A")
            sCommand = sCommand & "&Body=" & MessageBody
        End If
        
        rc = ShellExecute(GetDesktopWindow(), "Open", sCommand, "", App.path, 1)
        
    ErrHandler:
        If Err > 0 Then MsgBox Error$, , "Class CAppLog Function Email_Error()"
        
    End Function

    I didn't write the above code, but its purpose is to send an error report 2 myself when an error occurs. But it seems to work only SOME of the time. When it DOES work, an email pops up, populated with the information, and ready to send.

    WHen it DOESNT work, nothing happens, no email pops up, no error prompt, nothing.

    the only pattern i can see is that it always works at least the first time, and sometimes stops after that... and i have no idea why..

    any help debugging or code changes would be great. thanks

  2. #2
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,347
    this just uses mailto by the look of it - dodge and not a prob within vb itself as mailto is executed externally - if by sometimes you mean: "only on some computers" you may want to check the following :

    1) check that the user has an email program specified under the programs tab of the internet explorer properties window

    2) Make sure that the user has adiquite permission to send emails with outlook (in the group policies)

  3. #3
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,347
    btw: doens't mailto just open up an email ready 2 send? - not actually send it ??

  4. #4

    Thread Starter
    Fanatic Member SkiNLaB's Avatar
    Join Date
    Jan 2002
    Location
    Sydney, Australia
    Posts
    747
    yeah i said 'ready 2 send'

    by sometimes, i mean on the one computer, MY computer (and i have heard of others)

    it doesnt matter if restart outlook, or restart my project. once it stops working, it stops until i reset my computer.

    so those 2 things dont need 2 be checked do they, since it starts and stops on the same computers

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901
    what happens if you actually send it the first time? it shoud send it and get it out of the que, unless there is a problem.
    i'd try this to see if you actually get it. you may be missing something so that it keeps changing or appending info for the first one.

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