Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

mini email via telnet

Hi everyone,

I hope someone is going to be able to help me.

I need to make a small application using VB6 (enterprise Edition) to make a small email program.

On the form are the following:

textboxes x
1. txtmailfrom
2. txtmailto
3. txtmessage
4. txtport
5. txtserver

Command buttons x2
1. Exit Program (done and coded this one)
2. cmdsend

The way I want it to function is thus;
the user enters details in the text boxes and presses send the code behind cmdsend then prosesses and sends the email using telnet and the server and ports listed in the relevant boxes.

Is this possible and can someone guide me through the coding of it please ?

Comments

  • the walrusthe walrus Posts: 249Member
    [b][red]This message was edited by the walrus at 2005-2-24 9:42:5[/red][/b][hr]
    you probably want to use Winsock instead of Telnet. right click on your controls toolbar (where the textbox, command button, etc are) and click "Components...", then find "Microsoft Winsock Control" in the list and check it. Winsock allows you to send data over the internet pretty easily.

    to send mail you need to know SMTP (Simple Mail Transfer Protocol), but you're in luck, SMTP is very easy. (you didn't indicate whether you knew it or not in your post, so i dont know if you know it, you may already).

    Anyway, here's an example that should do what you want with a Winsock control named "ws". you will also need a listbox named "lstOut" to see the mail server's output (for debugging), and a textbox named "txtSubject" for the subject of the message.

    [code]
    Private Sub cmdSend_Click()
    ws.Close
    ws.Connect txtServer.Text, Val(txtPort.Text)
    lstOut.AddItem "Connecting to " & txtServer.Text & " on port " & txtPort.Text & "..."
    End Sub

    Private Sub ws_Close()
    ws.Close
    MsgBox "Communication complete, check lstOut to see whether mail was successfully sent."
    End Sub

    Private Sub ws_Connect()
    lstOut.AddItem "Connected"
    ws.SendData "HELO localhost" & vbCrLf
    ws.SendData "MAIL FROM:<" & txtFrom.Text & ">" & vbCrLf
    ws.SendData "RCPT TO:<" & txtTo.Text & ">" & vbCrLf
    ws.SendData "DATA" & vbCrLf
    ws.SendData "From:" & txtFrom.Text & vbCrLf
    ws.SendData "To:" & txtTo.Text & vbCrLf
    ws.SendData "Date:" & Date & vbCrLf
    ws.SendData "Subject:" & txtSubject.Text & vbCrLf
    ws.SendData "" & vbCrLf
    ws.SendData txtMessage.Text & vbCrLf
    ws.SendData "" & vbCrLf
    ws.SendData "." & vbCrLf
    ws.SendData "quit" & vbCrLf
    lstOut.AddItem "Sending Mail Request..."
    End Sub

    Private Sub ws_DataArrival(ByVal bytesTotal As Long)
    Dim gs As String, xArr() As String, xItem As Variant
    ws.GetData gs
    If InStr(gs, vbCrLf) Then
    xArr = Split(gs, vbCrLf)
    For Each xItem In xArr
    If Not xItem = "" Then lstOut.AddItem xItem
    Next
    Else
    lstOut.AddItem gs
    End If
    End Sub

    Private Sub ws_Error(ByVal Number As Integer, Description As String, _
    ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, _
    ByVal HelpContext As Long, CancelDisplay As Boolean)
    MsgBox Description, vbCritical, "Error"
    End Sub
    [/code]

    also, mail servers usually won't relay messages so you'll need to either use an SMTP server that you know works or use the SMTP server of the person you're sending it to. most smtp servers are set up on port 25.


Sign In or Register to comment.