Results 1 to 29 of 29

Thread: Sending Email from VB6 application

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2008
    Posts
    47

    Sending Email from VB6 application

    OS=Windows XP SP3; VB6-Enterprise Edition

    I have done a lot of searching for snippets of code that will allow a user to send an e-mail. I can not find what I need nor I don't understand the code.

    This is what I am looking to do:
    To make things easy, I'll have a menu item that will say "Send for Technical Support". What I want to happen when the user clicks on that menu item is for his/her email client to come up. When that window shows, I will have my e-mail address in the "To" and the words "Technical Support" in the Subject.
    All the user needs to do is to fill in the body of the text and send the e-mail. Control needs to return back to the VB application.

    Can anyone help me out with a sample of code or the actual code I need to write.

    Thank you,
    Sam

  2. #2

  3. #3
    PowerPoster
    Join Date
    May 2006
    Location
    Location, location!
    Posts
    2,673

    Re: Sending Email from VB6 application

    However, if you want (as you asked) THEIR default email client to come up, a simple mailto: should suffice...done through a browser window, it usually invokes the default mail client. If you also want to add subject and stuff there's ways to do that, google "mailto options" and you should find more info :-)
    Well, everyone else has been doing it :-)
    Loading a file into memory QUICKLY - Using SendKeys - HyperLabel - A highly customisable label replacement - Using resource files/DLLs with VB - Adding GZip to your projects
    Expect more to come in future
    If I have helped you, RATE ME! :-)

    I love helping noobs with their VB problems (probably because, as an amateur programmer, I am only slightly better at VB than them :-)) but if you SERIOUSLY want to get help for free from a community such as VBForums, you have to first have a grounding (basic knowledge) in VB6, otherwise you're way too much work to help...You've got to give a little if you want to get help from us, in other words!

    And we DON'T do your homework. If your tutor doesn't teach you enough to help you make the project without his or her help, FIND A BETTER TUTOR or try reading books on programming! We are happy to help with minor things regarding the project, but you have to understand the rest of it if you want our help to be useful.

  4. #4
    Member
    Join Date
    Mar 2005
    Location
    SouthEastern PA
    Posts
    39

    Re: Sending Email from VB6 application

    Quote Originally Posted by RhinoBull View Post
    vbSendMail is arguably best free email client out there.
    It uses winsock and is very simple to implement so give it a try.
    The instructions state "You also need a reference to the vbSendMail component in the Project References"

    Question: Where do I find the references for vbSendMail and how do I put them in Project Reference area?

  5. #5
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Sending Email from VB6 application


  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Sending Email from VB6 application

    Quote Originally Posted by SamC View Post
    The instructions state "You also need a reference to the vbSendMail component in the Project References"

    Question: Where do I find the references for vbSendMail and how do I put them in Project Reference area?
    Reference becomes available after dll gets registered.
    I thought someone who does this [apparently] since 2005 would know that.
    Besides, zip file contains VBG files which stand for VBGroup so when it is loaded it will include multiple projects - one of them is "main" and one is dll.
    Your main project will already have dll referenced so all you need to do is run it.

    Regards.

  7. #7
    Member
    Join Date
    Mar 2005
    Location
    SouthEastern PA
    Posts
    39

    Re: Sending Email from VB6 application

    Okay: I added vbsendmail.dll to system32 directory and created the "References" entry.

    Here's the code I copied and ran:
    Code:
    Private WithEvents poSendMail As vbSendMail.clsSendMail
    Private Sub cmdSend_Click()
    'Assumes you have a form with text boxes named as below
    
    Set poSendMail = New vbSendMail.clsSendMail
    poSendMail.SMTPHost = txtServer.Text
    poSendMail.From = txtFrom.Text
    poSendMail.FromDisplayName = txtFromName.Text
    poSendMail.Recipient = txtTo.Text
    poSendMail.RecipientDisplayName = txtToName.Text
    poSendMail.ReplyToAddress = txtFrom.Text
    poSendMail.Subject = txtSubject.Text
    poSendMail.Attachment = txtFileName.Text 'attached file name
    poSendMail.Message = txtMsg.Text
    poSendMail.Send
    Set poSendMail = Nothing
    End Sub
    Looking at this statement
    Code:
    poSendMail.SMTPHost = txtServer.Text
    How do I find this value?

    I am confused with this: For example: User1 might be using Outlook; User2 might be using Incredimail. The SMTP host will vary. So programmatically, how do I find the value?

    Sam

  8. #8

  9. #9
    Member
    Join Date
    Mar 2005
    Location
    SouthEastern PA
    Posts
    39

    Re: Sending Email from VB6 application

    Quote Originally Posted by RhinoBull View Post
    You don't - it's a user input field. Here is list of major providers.
    I'm sorry but I'm, still confused. I saw the list of Servers but I don't know what to do with it.

    If I plug the Server Name in the textbox, How do I determine what server the user has?

    I need some "hand holding".If you can explain it in a few lines of code, I would appreciate it.

    Sam

  10. #10
    Frenzied Member
    Join Date
    May 2006
    Location
    some place in the cloud
    Posts
    1,886

    Re: Sending Email from VB6 application

    From wikipedia
    While electronic mail servers and other mail transfer agents use SMTP to send and receive mail messages, user-level client mail applications typically only use SMTP for sending messages to a mail server for relaying...
    ...as I understand, the 'user' send the mail as a message to the SMTP server typed in the textbox and this SMTP server actually send the mail

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sending Email from VB6 application

    look at the setting used by the current email client, it is generally related to the isp providing service,

    vbsendmail does try to determine the default client without input from the user, sometimes works sometimes does not

    if they have no smtp server available, the user would have to look at setting up an account for one, with a free service such as gmail or gmx
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12
    Member
    Join Date
    Mar 2005
    Location
    SouthEastern PA
    Posts
    39

    Re: Sending Email from VB6 application

    MAYBE, I am approaching this problem the WRONG WAY. Let me ask those of you with experience how you would handle this problem.

    This is what I am trying to do:
    I am writing an application that will be distributed to many users. If they run into any problems, I want to be notified. I have seen in many applications, usually in the "HELP" menu a link that might say "For Support...." or on a form, a Text box that would say "Enter your e-mail address". When the link is clicked your clients e-mail comes up and the user types in the body and sends the e-mail. Control returns back to the program.

    Now, I DO NOT NEED TO DO IT THIS WAY but I am asking you professionals how I should handle the problem. Maybe this is more of a "design" question? If you wrote an an application and the user had a problem, how would you tell the user to contact you? Would you just give them an e-mail address or would you enhance that by bringing up the user's e-mail client OR would you do it a totally different way? If so, how?

    Thanks,
    Sam

  13. #13
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending Email from VB6 application

    how would you tell the user to contact you
    transferring the error details to a webserver or developer by email

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  14. #14
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending Email from VB6 application

    Try logging all errors to a text file and send it to the webserver or send it as an email to you..

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  15. #15
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sending Email from VB6 application

    for the user to contact you
    you can use mailto: from shellexecute to fill an email in there default email client, to which they can add more information, then click send, this is probably the most useful method

    to autosend details or log files, in background with no user interface i would use cdo.message, but vbsendmail would work as well, if unsure about the users stp server you could send all, from an account of your own from some free stmp server such as gmail or gmx
    you can not use vbsendmail with gmail as gmail uses ssl, but there is code samples in this forum for using cdo.message to send through gmail
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  16. #16
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Sending Email from VB6 application

    I have a problem with this too.
    i've downloaded some source code, included the vbmaildll.
    no success at all.
    vbmaildll is the only program that show me exactly the reason of fail.
    the reason is issue STARTTSL,
    i looked in google, and i understand this is some format you need to include in the mail, but i couldn't figure out how.
    maybe someone know something ?

    EDIT: in general what i'm trying to do is, send a mail to valid email, from my pc, without login to some mail first.
    is this possible ?

  17. #17
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sending Email from VB6 application

    afaik
    tsl is a secure socket, vbsendmail does not support secure sockets, you would need to modify the source code of the sendmail application
    or use some alternative

    like Secure Socket Layers (SSL) and Transport Security Layer (TSL), ...
    send a mail to valid email, from my pc, without login to some mail first
    you always have to login to some server, though it can be done in background
    Last edited by westconn1; Jan 7th, 2010 at 05:27 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  18. #18
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending Email from VB6 application

    @westconn1: I think setting the port to 465 will work... Not sure about this... I have faced the same problem, when a Gmail account is used in vbsendmail...

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  19. #19
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sending Email from VB6 application

    i have no problem doing that in cdo, but have never had success in vbsendmail
    cdo has a setting to use ssl
    Last edited by westconn1; Jan 7th, 2010 at 05:40 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  20. #20
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Sending Email from VB6 application

    wetscon1
    i found this
    Code:
    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = "Example CDO Message"
    objMessage.From = "[email protected]"
    objMessage.To = "[email protected]"
    objMessage.TextBody = "This is some sample message text."
    objMessage.Send
    but it fails with run time error
    that the senduse doesn't set or somthing.
    can you please post a working example
    how to send simple text, (+ maybe one attach file)
    to hotmail.com/gmail.com
    the smtp is

    smtp.live.com
    smtp.gmail.com

    (incase you forgot )
    thanks ahead.

  21. #21
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: Sending Email from VB6 application

    See this thread: CDO Mail

    westconn1 had posted some code: westconn1's reply

    For more, do a search on the forums for CDO

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  22. #22
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Sending Email from VB6 application

    thank you very much.
    yes, the code of westconn1 works fine for gmail.com

    and this can be enough for what i need,
    though i would like to know, how to access smtp.live.com too.

    i hope there is an option to configure tsl connection in cdo.
    if someone know, please help
    Last edited by whatsup; Jan 8th, 2010 at 03:05 AM.

  23. #23
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sending Email from VB6 application

    usessl parameter (as set in the code for gmail) should work, gmail uses a secure server, change the server and port etc to suit whatever server you wish to use

    if the user has a smtp email client already set up you can default the code to use that default server, but sendusing = 2 is required (use transport, for all external emails)
    there is some constants used for sendusing (and other values), but i can not remember what they are
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  24. #24
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Sending Email from VB6 application

    thanks man, but i have to tell you something.

    about 2 days ago, i could quite easy success with send to gmail.com

    today i spent about 2 hours, trying to send , with a cleaner code, but couldn't successed.
    after about 2 hours i looked into the mail, in the recieved mails that i did
    2 days ago, and i got it.
    your code has only one problem.
    the "to" field has to be a valid email address.
    i mean it can't be "me" as in your code, but it can be "[email protected]"

    wow, at least i found it,
    now other time i'll check the live.com server.

    so please fix your code, so others won't spent hours like me

    anyway thank you very much for your code, it was a really great help for me,
    i was badly needed it.

  25. #25
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Sending Email from VB6 application

    i did assume anyone using the code would at least try sending to a valid email address
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  26. #26
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Sending Email from VB6 application

    Not sure if this would be of help but the mail retrieval project in my sig shows how to use Visual Basic 6.0 to send an email through Office Outlook.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  27. #27
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Sending Email from VB6 application

    Quote Originally Posted by whatsup View Post
    I have a problem with this too.
    i've downloaded some source code, included the vbmaildll.
    no success at all.
    vbmaildll is the only program that show me exactly the reason of fail.
    the reason is issue STARTTSL,
    i looked in google, and i understand this is some format you need to include in the mail, but i couldn't figure out how.
    maybe someone know something ?

    EDIT: in general what i'm trying to do is, send a mail to valid email, from my pc, without login to some mail first.
    is this possible ?
    vbSendMail has WithEvents to trap errors:

    Code:
    Option Explicit
    Private WithEvents poSendMail As vbSendMail.clsSendMail
    
    Private Sub Command1_Click()
        Call SendNotificationEmail("x", "Test", "test subject")
    End Sub
    
    Private Sub poSendMail_SendFailed(Explanation As String)
    
        MsgBox ("Your attempt to send mail failed for the following reason(s): " & vbCrLf & Explanation)
    
        
    End Sub
    
    Private Sub SendNotificationEmail(ByVal pTo As String, _
                                            ByVal pMessage As String, _
                                            ByVal pSubject As String, _
                                            Optional ByVal pCC As String = "")
                
    10    On Error GoTo ErrorHandler
                      
    20        Set poSendMail = New vbSendMail.clsSendMail
    30        poSendMail.SMTPHost = "Yourhost.com"
    40        poSendMail.From = "[email protected]"
    50        poSendMail.FromDisplayName = "DoNotReply.com"
    60        poSendMail.Recipient = "[email protected]"
    70        poSendMail.CcRecipient = "[email protected]"
    80        poSendMail.Subject = pSubject
    90        poSendMail.Message = pMessage
    100       poSendMail.Send
    110       Set poSendMail = Nothing
    
    120       Exit Sub
              
    ErrorHandler:
    130       Err.Raise Err.Number, Err.Source & " [" & "SendEmailNotification Line: " & Erl & "]", Err.Description
    End Sub

  28. #28
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: Sending Email from VB6 application

    Quote Originally Posted by westconn1 View Post
    i did assume anyone using the code would at least try sending to a valid email address
    you are right, but i'm very new to internet stuff,
    so in the begining i didn't understand exactly what i'm doing.

    now i understand, and i also understand, that probably, there is no way
    to send a mail somewhere without login to a mail, first.

    so now i learned 2 things, how to login to a mail, and how to send a mail.
    thank you very much.

    now i need similar thing, login to messenger account through the web page, with winsock.
    sending request, waiting for respond and then sending the user name and password,

    the only problem is that i don't exactly how to do that, yet.
    Last edited by whatsup; Jan 13th, 2010 at 09:47 AM.

  29. #29
    Hyperactive Member danecook21's Avatar
    Join Date
    Feb 2008
    Location
    NC, USA
    Posts
    501

    Re: Sending Email from VB6 application

    Since the original question was how to bring up the default mail client with the TO and SUBJECT fields filled in, I have attached a sample project using ShellExecute to accomplish just that.
    Attached Files Attached Files

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