Results 1 to 10 of 10

Thread: having problems with winsock prog

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 1999
    Location
    Texas, US
    Posts
    45

    Post

    ok, here is my code....
    [code]
    Private Sub Command1_Click()
    Caption = "Sending Message.."
    If Winsock1.State <> sckClosed Then Winsock1.Close
    Winsock1.Connect """" & txtMailserver & """", 25
    End Sub

    Private Sub Winsock1_Connect()
    Winsock1.SendData "HELO " & Winsock1.LocalIP & vbCrLf & _
    "MAIL FROM: <" & txtMailFrom & ">" & vbCrLf & _
    "RCPT TO: <" & txTto & ">" & vbCrLf & _
    "DATA" & vbCrLf & _
    "TO: " & txTto & vbCrLf & _
    "FROM: " & txtFrom & vbCrLf & _
    "SUBJECT: " & txtSubject & vbCrLf & _
    txtmessage & vbCrLf & "." & vbCrLf & _
    "QUIT" & vbCrLf
    End Sub
    Private Sub Winsock1_SendComplete()
    Caption = "Send Complete."
    End Sub
    [\code]
    please correct this and send it back. I don't know what is wrong with it.
    [code]

    oh, it needs these....
    txtMailserver (where the user types in the mail server of course)
    txtMailFrom(gives the user the choice of entering their real adress or a fake adress)(this is where the user types in an email adress)
    txtfrom(this is where the user types in a name, real or fake, no matter)
    txtto(email adress of recipitent)
    txtsubject(DUH!)
    txtmessage(I think you can figure it out)
    winsock1(the winsock controll)
    command1(the "send email" button)
    [\code]

    problems.....
    no message shows up
    will not connect to mail server
    I'm not Sure what else....
    please help....

  2. #2
    New Member
    Join Date
    Oct 1999
    Location
    Michigan
    Posts
    15

    Post

    Have you built Error Handling routine to find if an error occurred.

    sckMain_Error(Number, Description, Scode, Source, HelpFile, HelpContext, CancelDisplay)

    deDogs

  3. #3
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892

    Post

    Play around with the mail server using Telnet...

    This is what I did to test it:

    Connect menu -> Remote System...
    Host Name: mail.netvision.net.il
    Port: 25
    (If you want to check for E-Mail, instead of 25 use POP3)
    TermType: vt100


    HELO Yonatan
    Server response: Hello (My IP goes here) , nice to meet you
    MAIL FROM: <[email protected]>
    Server response: <[email protected]>... Sender ok
    RCPT TO: <[email protected]>
    Server response: <[email protected]>... Recipient ok
    DATA
    Server response: Enter mail, end with "." on a line by itself
    TO: [email protected]
    FROM: [email protected]
    SUBJECT: Test message to myself...
    Testing... 1, 2, 3... Is this on?
    .

    Server response: DAA29262 Message accepted for delivery
    QUIT
    Server response: Closing connection

    Telnet MsgBox: Connection to host lost.

    After a few seconds I got my message just as I wanted it!

    Try it yourself, experiment with it and you'll be able to learn about how the E-Mail system works and how to use it from VB!

    Also, the Outlook Express program has an ability to keep track of all the commands it sends to/receives from the mail server and log them in a log file.
    Check the Mail CheckBox here:
    Tools menu -> Options -> Maintenance -> Troubleshooting -> Mail

    Afterwards, send or receive some mail using Outlook Express. When you are done experimenting (try sending an attachment, carbon copies, blind carbon copies, whatever) look for two files on your hard drive: POP3.LOG - all the commands sent to/received from the mail server regarding receiving E-Mail, and SMTP.LOG - all the commands sent to/received from the mail server regarding sending E-Mail.
    Don't forget to uncheck the CheckBox, because the two files can get really big!

    ------------------
    Yonatan
    Teenage Programmer
    E-Mail: [email protected]
    ICQ: 19552879
    AIM: RYoni69

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    I tried your code, and after I removed the quotes around the remotehost it worked fine. So I changed:
    Winsock1.Connect """" & txtMailserver & """", 25
    to
    Winsock1.Connect txtMailserver, 25

  5. #5
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    Frans C could I see the final code you used?
    I've been wondering how to do this actually.
    Thanks.

    ------------------
    DiGiTaIErRoR

  6. #6
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    Sure! But all the credit goes to Charlezz. I just removed some quotes.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Caption = "Sending Message.."
        If Winsock1.State <> sckClosed Then Winsock1.Close
        Winsock1.Connect txtMailserver, 25
    End Sub
    Private Sub Winsock1_Connect()
        Winsock1.SendData "HELO " & Winsock1.LocalIP & vbCrLf & _
        "MAIL FROM: <" & txtMailFrom & ">" & vbCrLf & _
        "RCPT TO: <" & txtto & ">" & vbCrLf & _
        "DATA" & vbCrLf & _
        "TO: " & txtto & vbCrLf & _
        "FROM: " & txtfrom & vbCrLf & _
        "SUBJECT: " & txtsubject & vbCrLf & _
        txtmessage & vbCrLf & "." & vbCrLf & _
        "QUIT" & vbCrLf
    End Sub
    Private Sub Winsock1_SendComplete()
        Caption = "Send Complete."
    End Sub

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    Try to figure out where it goes wrong. Try adding some
    debug.print winsock1.state
    line at various points. This way, you can find out if the connection doesn't succeed or the sending gives the problems.
    Also try the error event of the winsock control. Further you could try to ping to the remote host, so your sure the address is ok. Maybe your provider doesn't listen to port 25, so you could try a different one (but this may be looking for a needle in a haystack).

    This is hard to debug from a distance.
    Sorry I couldn't do more.

  8. #8

    Thread Starter
    Member
    Join Date
    Sep 1999
    Location
    Texas, US
    Posts
    45

    Post

    That's ok, you've been a gret help, all of you!

  9. #9

    Thread Starter
    Member
    Join Date
    Sep 1999
    Location
    Texas, US
    Posts
    45

    Post

    I dont know why, but it still won't work, i click the button and it just says on the caption "sending message"

  10. #10
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: having problems with winsock prog

    The reason it is not working is because you are using the HTML entities &gt; and &lt; when sending the mail use < and > instead. You should also send the data one line at a time and ensure you receive a 200 OK reponse from each line, sometimes the mail server may refuse to send the e-mail.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

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