Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

winsock login

Posted on 2006-07-24
2
Medium Priority
?
262 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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

704 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