Solved

winsock login

Posted on 2006-07-24
2
254 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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now