Results 1 to 22 of 22

Thread: Mail from VB6 without MAPI

  1. #1

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Mail from VB6 without MAPI

    There are many ways to sent email from VB, and while it is quite possible to do it with the MAPI control, i found a much simpler way, using a webbrowser control and an ASP page. My code simply retrieves the to, from, subject and body information from the url. To use it, you just create an invisble web browser in the form, and then with a little string manipulation, you can navigate to the webbrowser with all the info necessary to send the email.

    The page is on my site at www.startingqbasic.co.uk/aspmailer.asp.

    To use it, add values for to=,from=,subject= and body= values to the url and there you go. I use this vb code:


    VB Code:
    1. Private Sub sendmailbutton_Click()
    2. Dim mailurl As String
    3.  
    4. mailurl = "http://www.startingqbasic.co.uk/aspmailer.asp?"
    5. ' that line sets the start of the page string
    6.  
    7. mailurl = mailurl + "to=" + to_box.Text
    8. 'this adds the to details to the navigation string
    9.  
    10. mailurl = mailurl + "&" + "from=" + from_box.Text
    11. 'this adds the from details to the navigation string
    12.  
    13. mailurl = mailurl + "&" + "subject=" + subject_box.Text
    14. 'this adds the subject details to the navigation string
    15.  
    16. mailurl = mailurl + "&" + "body=" + body_box.Text
    17. 'this adds the subject details to the navigation string
    18.  
    19. mailbrowser.Navigate (mailurl)
    20. 'this navigates the webbrowser to the page
    21.  
    22. End Sub

    And thats it. It's free, and if you would like the asp code for it, just email and ask.

    KAZAR

  2. #2
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: Mail from VB6 without MAPI

    Thank u for this nice code. I am new to vb world. could u tell me how many text boxes do i need and what should i name them in order collect email ,subject ,... and submit button. I be happy if u help me out here.Furthermore, i be happy if u share the asp code with use.Thanks

  3. #3

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Mail from VB6 without MAPI

    well, the asp code i use is:

    Code:
     <%
    Dim tovar,fromvar,subjectvar,bodyvar,Mail
    Set Mail=Server.CreateObject("CDONTS.NewMail") 
    
    tovar=request.querystring("to")
    fromvar=request.querystring("from")
    subjectvar=request.querystring("subject")
    bodyvar=request.querystring("body")
    
    Mail.To=tovar
    
    Mail.From=fromvar
    Mail.Subject=subjectvar
    Mail.Body=bodyvar
    Mail.Send 
    Set Mail=nothing
    %>
    Text boxes in vb can be called anything you like, as long as you insert their text at the right point in the url.
    If you looked at the end url, it would look like:
    http://www.startingqbasic.co.uk/[email protected]&[email protected]&subject=ASP Mailer&body=ASP Mailer Test

    or something like that

    if you want to use it in a web page, then just name the textboxes to, from, subject and body, and use the get method, not the post.

    I hope that answers your question

  4. #4
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Mail from VB6 without MAPI

    you could use the INet control also

    VB Code:
    1. INet1.OpenURL "http://www.startingqbasic.co.uk/[email protected]&[email protected]&subject=ASP Mailer&body=ASP Mailer Test"
    Chris

  5. #5

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Mail from VB6 without MAPI

    True, but it doesn't differ functionality.

    You could have a sub that did this:
    VB Code:
    1. Sub sendmail()
    2. Dim MailInet as INet
    3. Dim mailurl As String
    4.  
    5. mailurl = "http://www.startingqbasic.co.uk/aspmailer.asp?"
    6. ' that line sets the start of the page string
    7.  
    8. mailurl = mailurl + "to=" + to_box.Text
    9. 'this adds the to details to the navigation string
    10.  
    11. mailurl = mailurl + "&" + "from=" + from_box.Text
    12. 'this adds the from details to the navigation string
    13.  
    14. mailurl = mailurl + "&" + "subject=" + subject_box.Text
    15. 'this adds the subject details to the navigation string
    16.  
    17. mailurl = mailurl + "&" + "body=" + body_box.Text
    18. 'this adds the body details to the navigation string
    19.  
    20. MailInet.OpenURL(mailurl)
    21. 'this opens the page with the dimmed inet control
    22. End sub

    That way you could just use it without having to create the INet Control First.

    I must point out however that I have found computers with the Inet Control Missing for whatever reason, not so with the webbrowser control.

  6. #6

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Mail from VB6 without MAPI

    Actually i have just been checking the inet control and it does work better.

    The effect is the same, but, if you are looping the function, ie, sending lots of emails at once, then you have to make your program wait if you use the webbrowser control, not so with the INet.

    So kudos and thanks to the182guy
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  7. #7
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: Mail from VB6 without MAPI

    This is genius

  8. #8
    Member Max bayne's Avatar
    Join Date
    Jul 2006
    Location
    Egypt
    Posts
    59

    Re: Mail from VB6 without MAPI

    gooooooooooooooood maaaaaaaaaaaan

  9. #9

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Mail from VB6 without MAPI

    thanks, tho this is a fairly old post. i still use this method tho.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  10. #10
    New Member MatrIxtheLovE's Avatar
    Join Date
    Jul 2006
    Location
    Viet Nam
    Posts
    3

    Re: Mail from VB6 without MAPI

    I want to send mail by VB6, but It have to use content of my programe and auto send after. can i help you?
    Nhẫn một chút gió yên sóng lặng
    Lùi một bước đất rộng trời cao

    [email protected]

  11. #11

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Mail from VB6 without MAPI

    You have to use code like this:

    VB Code:
    1. Option Explicit
    2. '''''''''''Notes on this sub'''''''''''
    3. 'At the moment you may only send text based data for the body argument, but eventually i will
    4. 'add a function to send HTML.
    5. '
    6. 'The good thing about the inet control is that it hangs the thread until it has
    7. 'finished, which makes it ideal for looping.
    8. '''''''''''''''''''''''''''''''''''''''
    9.  
    10. Sub SendMail(to_addr As String, from_addr As String, subject As String, data As String)
    11. Dim MailInet As INet
    12. Dim mailurl As String
    13.  
    14. mailurl = "http://www.startingqbasic.co.uk/aspmailer.asp?"
    15. ' that line sets the start of the page string
    16.  
    17. mailurl = mailurl + "to=" + to_addr
    18. 'this adds the to details to the navigation string
    19.  
    20. mailurl = mailurl + "&" + "from=" + from_addr
    21. 'this adds the from details to the navigation string
    22.  
    23. mailurl = mailurl + "&" + "subject=" + subject
    24. 'this adds the subject details to the navigation string
    25.  
    26. mailurl = mailurl + "&" + "body=" + data
    27. 'this adds the body details to the navigation string
    28.  
    29. MailInet.OpenURL (mailurl)
    30. 'this opens the page with the dimmed inet control
    31. End Sub
    32.  
    33. Sub SendAllData()
    34. 'Lets say you have 4 listboxes - one containing the to email addresses, another one the
    35. 'from email addresses, another one the subject and one more, with the data you wish to send
    36. Dim i As Integer
    37.  
    38. For i = 0 To to_listbox.ListCount - 1
    39.  
    40. SendMail to_listbox.List(i), from_listbox.List(i), subject_listbox.List(i), data_listbox.List(i)
    41.  
    42. Next i
    43. 'so, for each item in the listboxes (assuming the same number in each), then all the data in the listboxes
    44. 'will be sent to the corresponding addresses.
    45. 'note, there is a limit on how much data can be sent.  the advanced ones among you know that you can post data
    46. 'using winsock headers.  soon i will add a post function as well, which means that there is no limit
    47. End Sub
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  12. #12
    New Member
    Join Date
    Jun 2006
    Posts
    14

    Re: Mail from VB6 without MAPI

    Thanks a lot ~-=~-= KAZAR =-~=-~

  13. #13
    Lively Member
    Join Date
    Jul 2006
    Posts
    119

    Re: Mail from VB6 without MAPI

    I know this is preety old

    but how would one use the asp page >>?

    I mean where do I put it in my server!!??

    Code:
    <%
    Dim tovar,fromvar,subjectvar,bodyvar,Mail
    Set Mail=Server.CreateObject("CDONTS.NewMail") 
    
    tovar=request.querystring("to")
    fromvar=request.querystring("from")
    subjectvar=request.querystring("subject")
    bodyvar=request.querystring("body")
    
    Mail.To=tovar
    
    Mail.From=fromvar
    Mail.Subject=subjectvar
    Mail.Body=bodyvar
    Mail.Send 
    Set Mail=nothing
    %>
    Last edited by x2fusion; Jul 24th, 2006 at 08:38 PM.

  14. #14
    Lively Member
    Join Date
    Jul 2006
    Posts
    119

    Re: Mail from VB6 without MAPI

    Hello I been waiting days now /

    Anyways I learn my host don't support ASP .. Or SMTP on my plan anyways ..

    So any ideas on how to do it in PHP 4.x.x & So it don't need the local SMTP .. So it can remote ..

    O yes the mail() is disabled as well in PHP lol

    I want it so its like that below .. I mean so u can use it in VB still !!!
    Okays

  15. #15

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Mail from VB6 without MAPI

    Well, sorry for the lack of reply, but i have been on holiday.

    If you want to send the email from vb then you don't need to put it on your server. Just use my server's url. To use it online, then i shall add a thing so that you can attach a url to forward to after completing the mail send. Anyway, what kind of crap server doesn't have ASP, or php mailing on it?
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  16. #16
    Lively Member
    Join Date
    Jul 2006
    Posts
    119

    Re: Mail from VB6 without MAPI

    My host is http://awardspace.com }~

    & I'm on the free plan so I don't get the Mail() PHP funtion Or SMTP ..


    O an there still in beta so they don't support ASP yet I guess .


    & thx

  17. #17
    Lively Member
    Join Date
    Jul 2006
    Posts
    119

    Re: Mail from VB6 without MAPI

    Hello you need to fix this lol .
    http://www.startingqbasic.co.uk/aspmailer.asp


    Code:
    Microsoft VBScript compilation  error '800a03f2'
    
    Expected identifier
    
    /aspmailer.asp, line 42
    
    Upload.
    -------^

  18. #18

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Mail from VB6 without MAPI

    sorry i was working on it. it's fixed
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  19. #19
    Lively Member
    Join Date
    Jul 2006
    Posts
    119

    Re: Mail from VB6 without MAPI

    Ahh . What happend lol .

  20. #20

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Mail from VB6 without MAPI

    Nothing, but i had updated it, but had missed something
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

  21. #21
    Lively Member
    Join Date
    Jul 2006
    Posts
    119

    Re: Mail from VB6 without MAPI

    Ohh . What you update >
    ?

  22. #22

    Thread Starter
    Hyperactive Member kazar's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    323

    Re: Mail from VB6 without MAPI

    I was adding an attachment function, but it isn't finished yet. Still got some bugs to iron out.
    KAZAR

    The Law Of Programming:

    As the Number of Lines of code increases, the number of bugs generated by fixing a bug increases exponentially.
    __________________________________
    www.startingqbasic.co.uk

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