Results 1 to 25 of 25

Thread: How can I send automatic e-mails with VB6?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    PORTUGAL
    Posts
    18

    Question

    I want to send e-mails from my routines in VB6 but I don't know how without need to be there to press SEND button.
    How can I do this with Eudora or any kind of e-mail program?
    Eng. José Nogueira
    Mail: [email protected]
    Web: planeta.clix.pt/janogueira
    Entroncamento-Santarém-PORTUGAL

  2. #2
    Guest
    You might try the ShellExecute API call. It causes the OS to launch appropriate programs based on file types/extensions.

    In a regular .BAS module declare the function:

    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

    And in your code use something like:

    Dim lngResult
    lngResult = ShellExecute(Me.hwnd, "Open", "mailto:[email protected]", "", "", vbNormalFocus)

    This would cause your browsers default email client to open up a new message addressed to [email protected].

    If you wanted email to automatically be sent from your application (without user intervention) you'd likely need an object library for the software you wanted to send with, like using the Outlook Object Library for sending via Outlook/Exchange.

    Good luck,
    Paul

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    You can easily send a message by declaring Outlook objects. You will have to determine what/when to send. You did not indicate why you want to send an email to someone.

    Do you want to notify someone when a particular event occurs? Do you want to send out regulary scheduled messages? If so, just call a procedure to send the email when the event does occur. I am doing that now with a process monitor interface. Using Outlook, I send text pages to the appropriate people when there is an event that needs immediate attention.

    Try something like this:
    Code:
    Private Sub Auto_Send()
       Dim objOutlook As New Outlook.Application
       Dim objOutlookMsg As Outlook.MailItem
    
       'Create new message
       Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    
       ' Set all desired Outlook properties
       With objOutlookMsg
        .To = "userid@users_address"
        .Subject = "Automated email test"
        .Body = "This is line 1" & vbNewLine
        .Body = .Body & "This is line 2" & vbNewLine
        .Importance = olImportanceHigh
        .Send
       End With
    
       Set objOutlookMsg = Nothing
    
       'Close Outlook instance: Important!
       Set objOutlook = Nothing
    
       MsgBox "Auto Email Complete", vbInformation
    
    End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    PORTUGAL
    Posts
    18

    Unhappy E-mail auto send with VB6

    PWNettle as sent me an interesting code. It results but I have to little observations:
    1. I can't post the Subject into the e-mails
    2. It only has utility for me if it would send my e-mail automaticly because I'm not in there to click the SEND Button.
    I use Eudora or Microsoft Outlook. Who can help me? I will change my e-mail browser if someone knows how to do so with another one.

    My best regards

    José Nogueira - PORTUGAL
    Eng. José Nogueira
    Mail: [email protected]
    Web: planeta.clix.pt/janogueira
    Entroncamento-Santarém-PORTUGAL

  5. #5
    Guest
    Um, use ccoder's example of how to use Outlook.

    Paul

  6. #6
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    I think the best way to send emails is by using winsock. http://www.vbsquare.com/articles/sendmail/
    Oetje
    [email protected]
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  7. #7

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    PORTUGAL
    Posts
    18

    Unhappy Mswinsck.ocx missing file

    I'm trying the OETJE code but I can't found the Mswinsck.ocx file in my machine.
    So, my VB6 compiler doesn't compile and link it.
    Who can send me this missing file?

    My best regards

    José Nogueira
    Eng. José Nogueira
    Mail: [email protected]
    Web: planeta.clix.pt/janogueira
    Entroncamento-Santarém-PORTUGAL

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    PORTUGAL
    Posts
    18

    Talking E-mailing...

    The code suggested by OETJE really works. It the most useful code I ever seen since I programm in VB6.

    My best regards for OETJE and for this Forum

    José Nogueira
    Eng. José Nogueira
    Mail: [email protected]
    Web: planeta.clix.pt/janogueira
    Entroncamento-Santarém-PORTUGAL

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    PORTUGAL
    Posts
    18

    Unhappy I compile and link but it doesn't work.

    I tried the code OETJE noticed and it works.
    However, it had not worked initialy because I had not checked the Winsock component in the object bar.
    After doing that I finally compiled and linked this code.
    To soon for a party...
    The prelinked exe file already works, the vbp file is compilable and linkable but after that it doesn't work because it answers me "Run-time error '13': type mysmatch!". I try to do a Step by Step running and this error is concerned with the code line "ConnectToServer txtServer.Text, Winsock1", where it stops. However, sometimes my VB6 doesn't compile and tells me "Compile error: variable not defined!" pointing to "Winsock1" code of line "ConnectToServer txtServer.Text, Winsock1", the same of the last problem.

    WHO CAN HELP MEEEEEEE? I'm one little step from my objective.

    My best regards

    José Nogueira
    Eng. José Nogueira
    Mail: [email protected]
    Web: planeta.clix.pt/janogueira
    Entroncamento-Santarém-PORTUGAL

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Oct 2000
    Location
    PORTUGAL
    Posts
    18

    Unhappy Please, don't forget me !!!

    Please, don't forget me. Who can help me?

    José Nogueira
    Eng. José Nogueira
    Mail: [email protected]
    Web: planeta.clix.pt/janogueira
    Entroncamento-Santarém-PORTUGAL

  11. #11
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: How can I send automatic e-mails with VB6?

    hi,
    kinda new hir...

    i tried the ccoder's code, i encounter an error,

    "A program is trying to automatically send email on your behalf.
    Do you want to allow this?

    If this is unexpected, it may be a virus and you should choose 'No'.

    buttons <Yes> <No> <Help>"

    can it be automatically? i mean i think it should not prompt like that...

    thanks,
    toto

  12. #12
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: How can I send automatic e-mails with VB6?

    That is due to some security changes that Microsoft implemented several years ago.

    You may want to consider using SMTP. Take a look at the code that I posted here.

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

    Re: How can I send automatic e-mails with VB6?

    @ccoder

    i downloaded your sample from the link above, but i need to find out how to put recipient & sender address and subject, you done any of that?

    ok i just found the code for that, was looking in the wrong place
    Last edited by westconn1; Sep 13th, 2007 at 07:22 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
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: How can I send automatic e-mails with VB6?

    i tried the link that you provided...

    but was not successfull in running the code, i've encountered an error stating:

    "Run-time error '40006':
    Wrong protocol or connection state for the requested transaction or request"

    why is it like that?
    but i can send email using OUTLOOK, using the same SMTP host name...

    please help...

  15. #15
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: How can I send automatic e-mails with VB6?

    Use Microsoft CDO. It will not prompt a messagebox if you are sending e-mails.

    Rate Me! Rate Me! Rate Me!

    Time to fly.

    Copyright GraysonSoft Inc. 2007

  16. #16
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: How can I send automatic e-mails with VB6?

    hey tommy,

    can you spare some codes with it?

    thanks

  17. #17
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: How can I send automatic e-mails with VB6?

    Quote Originally Posted by toto_phl
    hey tommy,

    can you spare some codes with it?

    thanks
    Have you already included the Microsoft CDO Library in your Library?

    If so then hmmm........

    Let me seeee........

    Dang. It has been a long time since I programmed with VB 6 that I almost forgot to use CDO in VB6.

    Anyway, click on this link
    Last edited by tommygrayson; Sep 14th, 2007 at 03:03 AM. Reason: Corrected posting of link.
    Rate Me! Rate Me! Rate Me!

    Time to fly.

    Copyright GraysonSoft Inc. 2007

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

    Re: How can I send automatic e-mails with VB6?

    i was using cdo to send faxes previously, but i started getting security notification issues with it, so went to using other methods

    for all you ever wanted to know about cdo, try http://www.cdolive.com/default.htm
    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
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: How can I send automatic e-mails with VB6?

    i already added CDO in the reference...

    got the source code from the link you provided...

    but the part where it states the:

    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""

    it said that it should use the IP address, i dunno the IP. i only know the host name...

    is it the same?


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

    Re: How can I send automatic e-mails with VB6?

    Run-time error '40006':
    Wrong protocol or connection state for the requested transaction or request"
    this can be resolved by changing the sever address to an ip address

    to get the ip address, you can ping the server address or with winsock as after connecting the connection ip address is one of its properties
    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

  21. #21
    New Member
    Join Date
    Sep 2007
    Posts
    5

    Re: How can I send automatic e-mails with VB6?

    what if you don't know the IP address, only the host name?

    is it the same?

  22. #22
    Hyperactive Member tommygrayson's Avatar
    Join Date
    Aug 2005
    Location
    In my Nissan Silvia
    Posts
    433

    Re: How can I send automatic e-mails with VB6?

    Quote Originally Posted by toto_phl
    what if you don't know the IP address, only the host name?

    is it the same?
    You can determine the IP address of the host name by pinging it.

    You can also type the Host name instead of the IP name but it is not common practice.
    Rate Me! Rate Me! Rate Me!

    Time to fly.

    Copyright GraysonSoft Inc. 2007

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

    Re: How can I send automatic e-mails with VB6?

    i believe winsock needs to resolve the server address to a MX server to send mail, so if the server (hostname) you connect to is an A or other server it will fail to send mail, with the error you reported before, if you connect to the ip address of the server it will look at what servers are available, at that IP, to see if there is a MX server to connect to
    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
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: How can I send automatic e-mails with VB6?

    Quote Originally Posted by toto_phl
    i tried the link that you provided...

    but was not successfull in running the code, i've encountered an error stating:

    "Run-time error '40006':
    Wrong protocol or connection state for the requested transaction or request"

    why is it like that?
    but i can send email using OUTLOOK, using the same SMTP host name...

    please help...
    I can't help you until I get some more information.

    Did you make any changes other than filling in the 3 pieces of information that the program needs? These would be in the lines:
    Code:
      sckMail.RemoteHost = "smtp server address goes here"  ' supply server address
    
      addyList = "address1@domain1;address1@domain2"        ' supply address list (1 or more)
    
                sckMail.SendData "MAIL FROM:<sender@domain>" & vbCrLf  ' supply sender@domain
    Where in the code is the error occurring? What have you done up to that point?

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

    Re: How can I send automatic e-mails with VB6?

    @ ccoder, i got the same error when i put our server address in the format www.????????.com.au (as it is in outlook etc)
    when i put it in as an IP address it worked ok, (see my post above) as it resolved to the mail server
    but the test emails i sent mostly did not arrive (out of about 10 sent to 2 email addresses only 1 arrived) so i have to look at it some more
    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

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