Solved

winsock login

Posted on 2006-07-24
2
255 Views
Last Modified: 2010-05-18
hello,
I would like to test my email that I made in php with mydomain.com
and I just need a very little tool using winsock to connect
to mydomain.com and login using email@mydomain.com and pasword123..
how can I do this ?
0
Comment
Question by:aplelois
2 Comments
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 17169990
You can use INDY components. They have POP3/IMAP clients. Demos available at: http://www.indyproject.org/Sockets/Demos/index.en.aspx

If you want to use Sockets, you must have implementations of POP3/IMAP protocol. You have to perform the following:

1) Connect "mydomain.com" on port 110 (for POP3)
2) Send "USER username"
3) Send "PASS password"
4) Send "STAT" for mailbox status
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 500 total points
ID: 17173209
here's a TClientSocket demo I made for you
It's pretty basic, but should give you a good idea how to do what you want

Drop a TClientSocket, a TListbox, a TMemo, and a TButton on the form
then connect the button up to the Button1 "OnClick" event below
and connect the ClientSocket's "OnConnect", "OnDisconnect" and "OnRead" events to the socket events below also

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ScktComp; // <-- this unit is required for the TClientSocket

const
    stage_none = 0;
    stage_connected = 1;
    stage_sentuser = 2;
    stage_sentpass = 3;
    stage_sentstat = 4;
    stage_sentlist = 5;
type
  TForm1 = class(TForm)
    ClientSocket1: TClientSocket;
    Button1: TButton;
    Memo1: TMemo;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
    procedure ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket);
    procedure ClientSocket1Disconnect(Sender: TObject; Socket: TCustomWinSocket);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
    begin
        ClientSocket1.Tag := stage_none;
        ClientSocket1.Host := 'pop3.mydomain.com';
        ClientSocket1.Port := 110;
        ClientSocket1.Open;
    end;

procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
    var
        i: integer;
        s: string;
        sl: tstringlist;
    begin
        s := socket.ReceiveText;
        if s = '' then exit;
        memo1.lines.add(s);
        case ClientSocket1.Tag of
            stage_connected:
                begin
                    if pos('+OK', S) = 1 then
                    begin
                        ClientSocket1.Tag := stage_sentuser;
                        Socket.SendText('USER email@mydomain.com' +#13#10)
                    end
                    else
                    begin
                        memo1.lines.add('disconnecting due to logon error');
                        ClientSocket1.Close;
                    end;
                end;
            stage_sentuser:
                begin
                    if pos('+OK', S) = 1 then
                    begin
                        ClientSocket1.Tag := stage_sentpass;
                        Socket.SendText('PASS password123' +#13#10);
                    end
                    else
                    begin
                        memo1.lines.add('disconnecting due to logon error');
                        ClientSocket1.Close;
                    end;
                end;
            stage_sentpass:
                begin
                    if pos('+OK', S) = 1 then
                    begin
                        ClientSocket1.Tag := stage_sentstat;
                        Socket.SendText('STAT' +#13#10);
                    end
                    else
                    begin
                        memo1.lines.add('disconnecting due to logon error');
                        ClientSocket1.Close;
                    end;
                end;
            stage_sentstat:
                begin
                    if pos('+OK', S) = 1 then
                    begin
                        ClientSocket1.Tag := stage_sentlist;
                        Socket.SendText('LIST' +#13#10);
                    end
                    else
                    begin
                        memo1.lines.add('disconnecting due to STAT error');
                        ClientSocket1.Close;
                    end;
                end;
            stage_sentlist:
                begin
                    sl := tstringlist.create;
                    try
                        sl.Text := s;
                        for i := 0 to pred(sl.count) do
                        begin
                            if pos('.', SL[i]) = 1 then
                            begin
                                memo1.lines.add('finished LIST, so closing now');
                                ClientSocket1.Close;
                            end // otherwise we just display the list until we get the dot line
                            else if pos('+OK', SL[i]) <> 1 then
                              listbox1.items.add(SL[i]);
// if we wanted to do anything with the list, we could do it here...for now i'll just stick it in a listbox

                        end;
                    finally
                        sl.clear;
                        sl.free;
                    end;
                end;
            end;
    end;

procedure TForm1.ClientSocket1Connect(Sender: TObject; Socket: TCustomWinSocket);
    begin
        ClientSocket1.Tag := stage_connected;
        memo1.lines.add('connected');
    end;

procedure TForm1.ClientSocket1Disconnect(Sender: TObject; Socket: TCustomWinSocket);
    begin
        ClientSocket1.Tag := stage_none;
        memo1.lines.add('disconnected');
    end;

end.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question