Results 1 to 15 of 15

Thread: [RESOLVED] Send an email

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    Resolved [RESOLVED] Send an email

    As a VB6 developer, I have to email my boss a summary of my activity for the week.

    So far I am just writing it to a doc file during the week, then doing a copy-paste into her email account on Friday.

    I could just have my VB6 app email directly into her account.

    How would I do this ?

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

    Re: Send an email

    You mean like just use the File menu > Send menu item or something else because its as direct as you can get.
    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

  3. #3
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: Send an email

    Quote Originally Posted by RobertLees
    As a VB6 developer, I have to email my boss a summary of my activity for the week.

    So far I am just writing it to a doc file during the week, then doing a copy-paste into her email account on Friday.

    I could just have my VB6 app email directly into her account.

    How would I do this ?
    i use such a feature in my program that sends docs in a flash by email mail to any one. here is the code.

    This code uses gmail SMTP to deliver the mails.
    Code:
    Private Sub Form_Load()
    
    'Add the Project Reference Miscrosoft CDO WINDOWS FOR 2000
    
    Dim lobj_cdomsg As CDO.Message
    Set lobj_cdomsg = New CDO.Message
    
    With lobj_cdomsg.Configuration
    .Fields(cdoSMTPServer) = "smtp.gmail.com"
    .Fields(cdoSMTPConnectionTimeout) = 60
    .Fields(cdoSendUsingMethod) = cdoSendUsingPort
    .Fields(cdoSMTPServerPort) = 465
    .Fields(cdoSMTPAuthenticate) = True
    .Fields(cdoSMTPUseSSL) = True
    .Fields(cdoSendUserName) = "[email protected]" ' 
    .Fields(cdoSendPassword) = "XXXXXXX="
    
    lobj_cdomsg.To = "[email protected]"
    lobj_cdomsg.From = "[email protected]"
    lobj_cdomsg.Subject = "TEST MESSAGE "
    lobj_cdomsg.TextBody = "body text"
    'lobj_cdomsg.AddAttachment ("c:\test.txt")
    
    
    .Fields.Update
    lobj_cdomsg.Send
    End With
    
    
    
    Set lobj_cdomsg = Nothing
    MsgBox "send"
    End Sub
    PLS convert this code to a nice function
    Last edited by Fazi; Dec 24th, 2008 at 03:37 AM.

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

    Re: Send an email

    My Fav example on sending Mail with a File Attachment....

    http://www.example-code.com/vb/vbSimpleSend.asp
    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

  5. #5
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Send an email

    I was using vbsendmail, but users were having a hard time setting all the requirements, smtp server, pop server, authenication etc.
    My software sends rtf invoices, proposals, etc
    This is fast and easy:
    Save your message to a rtf file then
    Or save to a text file
    Make a reference to Microsoft windows cdo library
    Code:
    Dim objMessage
    Set objMessage = CreateObject("CDO.Message")
    
    With objMessage
    .To = "To email"
    .Subject = "your Subject"
    .From = "From email"
    .AddAttachment =  txtAttach 'Textbox holding path to attachment 
    .Send
    End With
    The only drawback is there is no way to determine if the message was sent, it just sends it.
    Last edited by isnoend07; Dec 24th, 2008 at 12:05 PM.
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    Re: Send an email

    Thanks guys.

    They all sounded good, but for different reasons they didn't work.

    Fazi, I got this

    Run-time error

    The message could not be sent to the SMTP server. The transport error code was ox80040217. The server response was not available.

    koolsid, that method required a 3rd party activeX that had a 30 day trial.

    isnoend07, just did nothing. I didn't use the attachment line. It wasn't mandatory was it ?

  7. #7
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Send an email

    Quote Originally Posted by RobertLees
    Thanks guys.

    They all sounded good, but for different reasons they didn't work.

    Fazi, I got this

    Run-time error

    The message could not be sent to the SMTP server. The transport error code was ox80040217. The server response was not available.

    koolsid, that method required a 3rd party activeX that had a 30 day trial.

    isnoend07, just did nothing. I didn't use the attachment line. It wasn't mandatory was it ?
    The attachment isn't necessary. Did you check your email. it's very fast
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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

    Re: Send an email

    to use cdo.message you must either, to use the code by isnoend, have a default smtp server set up by your default email client, or using the code posted by fazi, have a valid gmail account, and have your code in the configuration match the account settings
    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

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    Re: Send an email

    I tried faji's method - I do have a gmail account - but I got this..

    The message could not be sent to the SMTP server. The server response was not available.

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

    Re: Send an email

    post the code you are using, an indicate which line you get error
    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

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    Re: Send an email

    The code I used was......

    With lobj_cdomsg.Configuration
    .Fields(cdoSMTPServer) = "smtp.gmail.com"
    .Fields(cdoSMTPConnectionTimeout) = 60
    .Fields(cdoSendUsingMethod) = cdoSendUsingPort
    .Fields(cdoSMTPServerPort) = 465
    .Fields(cdoSMTPAuthenticate) = True
    .Fields(cdoSMTPUseSSL) = True
    .Fields(cdoSendUserName) = "[email protected]" '
    .Fields(cdoSendPassword) = strPassword & "="

    lobj_cdomsg.To = "[email protected]"
    lobj_cdomsg.From = "[email protected]"
    lobj_cdomsg.Subject = strSubject
    lobj_cdomsg.TextBody = strBody
    lobj_cdomsg.AddAttachment strAttachmentLocation

    .Fields.Update
    lobj_cdomsg.Send
    End With

    At the Send command I got this....
    The message could not be sent to the SMTP server. The transport error code was ox80040217. The server response was not available.

  12. #12
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: Send an email

    Quote Originally Posted by RobertLees
    The code I used was......

    With lobj_cdomsg.Configuration
    .Fields(cdoSMTPServer) = "smtp.gmail.com"
    .Fields(cdoSMTPConnectionTimeout) = 60
    .Fields(cdoSendUsingMethod) = cdoSendUsingPort
    .Fields(cdoSMTPServerPort) = 465
    .Fields(cdoSMTPAuthenticate) = True
    .Fields(cdoSMTPUseSSL) = True
    .Fields(cdoSendUserName) = "[email protected]" '
    .Fields(cdoSendPassword) = strPassword & "="

    lobj_cdomsg.To = "[email protected]"
    lobj_cdomsg.From = "[email protected]"
    lobj_cdomsg.Subject = strSubject
    lobj_cdomsg.TextBody = strBody
    lobj_cdomsg.AddAttachment strAttachmentLocation

    .Fields.Update
    lobj_cdomsg.Send
    End With

    At the Send command I got this....
    The message could not be sent to the SMTP server. The transport error code was ox80040217. The server response was not available.
    I had that problem when i was trying to get the smtp server from google to work with vbsendmail. Try using your isp's smtp server
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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

    Re: Send an email

    why the "=" at the end of the password??

    i don't have my code here, but i have certainly sent with gmail before, and i know there is code examples on this forum, a search on cdo.message should bring up a working example
    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
    Hyperactive Member
    Join Date
    Sep 2005
    Location
    Wellington, NZ
    Posts
    267

    Re: Send an email

    The = was in Fazi's example. I removed it and BINGO.

    That's guys. On the my next problem

  15. #15
    PowerPoster Fazi's Avatar
    Join Date
    Aug 2005
    Location
    Underworld
    Posts
    2,525

    Re: [RESOLVED] Send an email

    oh that = is a charactor in my gmail password
    I should have deleted that. sorry sorry

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