Solved

winsock login

Posted on 2006-07-24
2
257 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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