Results 1 to 29 of 29

Thread: [RESOLVED] Send email through VB?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Resolved [RESOLVED] Send email through VB?

    Hi everybody,
    I want to send an email to multi users through my VB application.
    How do I do that? (my email account is gmail.)
    Thank you
    Tova

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Send email through VB?

    What version of VB?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Question Re: Send email through VB?

    Vb 6.0

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Send email through VB?

    In that case your thread would be better in our "VB6" forum (as there is no particular reason to use API's to do what you want), so I've moved the thread there.

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Send email through VB?

    Are you sending multiple copies or are you sending all different messages?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Question Re: Send email through VB?

    Different messages.
    I need to send an email through my VB application.
    If I find out how to send 1 email to 1 addressee that would be great.
    I found several code samples on the internet, but they all lack the info how to setup the library that they use. Some mention that the library need to be purchased. I need a free option.
    Is MAPI free? How do I get it, install it, make my VB app recognize it?
    Thanks
    Tova

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

    Re: Send email through VB?

    check out this thread for using cdo.message with gmail
    http://www.vbforums.com/showthread.p....message+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

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Unhappy Re: Send email through VB?

    I get: Compile error: User defined type not defined
    About the: CDO.Message .
    How do I define it?

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Send email through VB?

    set a refrerence to the CDO dll. It was in the code snip: "'Add the Project Reference Miscrosoft CDO WINDOWS FOR 2000"

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Re: Send email through VB?

    Excuse my ignorance, but how do I set a reference to a dll?
    And is it a dll supposed to be on my computer, or be downloaded from the net?

  11. #11
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Send email through VB?

    Yes you need to have the dll and any of its dependancies.

    To add a reference...

    Project > References... > scroll through your list and find "Microsoft CDO for Windows 2000 Library" (cdosys.dll) > check its box > click OK. Done
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  12. #12

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Red face Re: Send email through VB?

    The closest I have on that list is: Microsoft CDE for Exchange 200 library. (cdoex.dll)
    Should it work?
    I downloaded cdosys.dll from the net, and placed it at same folder as cdoex.dll, but that doesn't put it on the project references list.
    Help.
    Thanks
    Tova

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

    Re: Send email through VB?

    cdo is part of windows xp (and other) default install
    try this to see if it works
    vb Code:
    1. Set omsg = CreateObject("cdo.message")
    2. MsgBox omsg.configuration.fields("http://schemas.microsoft.com/cdo/configuration/smtpaccountname")
    3. Set omsg = Nothing
    this requires no references just paste in to a button or something and run
    the message box should give the name of your default smtp server,
    you will need to change this and other settings for gmail if you want to use that


    here is a complete code for gmail, using late binding, no reference required
    Code:
          Set objmessage = CreateObject("CDO.Message")
          objmessage.Subject = "Example CDO Message"
          objmessage.From = "[email protected]"
          objmessage.To = "me" ' sent to myself, not at gmail
          objmessage.TextBody = "This is some sample message text."
           
           objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
           
     
          'Type of authentication, NONE, Basic (Base64 encoded), NTLM
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    
          'Your UserID on the SMTP server
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "usernm"
           
          'Your password on the SMTP server
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "pass"
    
          'Name or IP of Remote SMTP Server
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
          'Server port (typically 25)
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
          'Use SSL for the connection (False or True)
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
          'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
          objmessage.Configuration.Fields.Update
    
    
          objmessage.Send
          Set objmessage = Nothing
    Last edited by westconn1; Aug 21st, 2009 at 03:08 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

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Unhappy Re: Send email through VB?

    The MsgBox displays nothing but the OK button.

  15. #15
    Hyperactive Member
    Join Date
    Aug 2008
    Posts
    382

    Re: Send email through VB?

    I tried it works...

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

    Re: Send email through VB?

    The MsgBox displays nothing but the OK button.
    that means no default stmp sever, but if you got no error then an object of CDO must have been created so if you use the code posted it should send email via 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

  17. #17

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Re: Send email through VB?

    Thanks! It works!
    But it only sends 128 emails and then fails.

    Could you let me know please, because I don't really have a way to check it myself:
    How much time do I need to wait between 128 email-sends to the next 128?
    And If I send same email message to many addressees, is there a limit on the number of addressees?
    What is the "right" way to send multiple emails?

    It is a library application. (Library - aka books lending library - check in check out application.) We need the application to send emails to all members who are late in returning books. Ideally, we want the list of specific books to be enumerated in the email. Which means different text for each member. But, in case it is much easier to send uniform text to all members who are late, we will consider that. If you can answer the above Qs, we will be able to make the wise decision.

    Thank you very much!
    Tova

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

    Re: Send email through VB?

    that maybe a limitation to gmail server (many servers have limits to stop spam)

    try sending 120, take a break then send next 120, etc
    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

  19. #19
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Send email through VB?

    It is a library application. (Library - aka books lending library - check in check out application.) We need the application to send emails to all members who are late in returning books. Ideally, we want the list of specific books to be enumerated in the email. Which means different text for each member. But, in case it is much easier to send uniform text to all members who are late, we will consider that. If you can answer the above Qs, we will be able to make the wise decision.
    Do you usually have 128 or more than 128 people who cross their due dates? Surprising... Sorry if I am being suspicious but I keep on seeing these kind of requests off and on...

    Edit: How big is your library and where is it located?
    Last edited by Siddharth Rout; Aug 24th, 2009 at 06:00 PM.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  20. #20

    Thread Starter
    Junior Member
    Join Date
    Aug 2009
    Posts
    16

    Smile Re: Send email through VB?

    Hi
    The library is located at Beit-Shemesh, Israel.
    I develop the application voluntarily.
    The application was copied to several smaller libraries.
    I expect 128 or more than 128 people who cross their due dates, initially when the send-emails-to-members-who-are-late functionality is new. I expect the number to decrese later, due to our better ability to remind them to return the books.
    Thanks!
    Tova

  21. #21
    Member
    Join Date
    Mar 2006
    Posts
    46

    Re: [RESOLVED] Send email through VB?

    Of course you could always use the Winsock control to send email. Might be a little hard to code but that way you could send a email with a none return address. i.e. [email protected] used to send a order to you but can't receive.

  22. #22
    Addicted Member
    Join Date
    Feb 2009
    Posts
    145

    Re: [RESOLVED] Send email through VB?

    hi, sorry to bump, how would this work for a non-gmail account, i will be using my domains smtp server to send emails, and just need a really simple few lines of code to send an email on an event in a piece of software i am writing...

    thanks

  23. #23
    Addicted Member
    Join Date
    Feb 2009
    Posts
    145

    Re: [RESOLVED] Send email through VB?

    hi, just tried what has been said in this post, but it fails straight away, this is the code I copied, and i get a 'comiple error, variable not defined' on the first line
    Code:
    Set omsg = CreateObject("cdo.message")
    This is the code I have, I have initially put it on a button to test:

    Code:
    Private Sub Command3_Click()
        Set omsg = CreateObject("cdo.message")
        MsgBox omsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpaccountname")
        Set omsg = Nothing
        Set objmessage = CreateObject("CDO.Message")
          objmessage.Subject = "Example CDO Message"
          objmessage.From = "my_email_address"
          objmessage.To = "my_test_email_address" ' sent to myself, not at gmail
          objmessage.TextBody = "This is some sample message text."
           
           objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
           
     
          'Type of authentication, NONE, Basic (Base64 encoded), NTLM
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    
          'Your UserID on the SMTP server
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusername") = "my_email_address"
           
          'Your password on the SMTP server
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypass"
    
          'Name or IP of Remote SMTP Server
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.gavinwatson.com"
          'Server port (typically 25)
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
          'Use SSL for the connection (False or True)
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
          'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
          objmessage.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 30
          objmessage.Configuration.Fields.Update
          objmessage.Send
          Set objmessage = Nothing
    End Sub
    Thanks in advance for any help!

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

    Re: [RESOLVED] Send email through VB?

    i presume you smtp would be using port 25
    and not requiring ssl (smtpusessl)
    try changing those
    local (isp) smtp servers often will work with the default configuration (no need to change any configuration fields)
    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

  25. #25
    Addicted Member
    Join Date
    Feb 2009
    Posts
    145

    Re: [RESOLVED] Send email through VB?

    But would that give me a variable not defined error?

    And yes, 25 and no ssl

  26. #26
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [RESOLVED] Send email through VB?

    The error "Variable not defined" means that you are trying to use a variable that has not been declared (a Dim line).

    In this case you should use the data type Object, so:
    Code:
    Dim omsg as Object

  27. #27
    Addicted Member
    Join Date
    Feb 2009
    Posts
    145

    Re: [RESOLVED] Send email through VB?

    aha! of course, sorry, and thanks!

    now i get this:

    runtime error -2147220973 (80040213)
    the transport failed to connect to the server

  28. #28
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] Send email through VB?

    that means what ever credentials you are using to logon to the SMTP server isn't correct. Could be a bad password, bad user name, or something like that.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  29. #29
    Addicted Member
    Join Date
    Feb 2009
    Posts
    145

    Re: [RESOLVED] Send email through VB?

    SPot on!

    Many thanks!

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