Solved

winsock login

Posted on 2006-07-24
2
259 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 80
Error E2158 compiling with Delphi XE10 Seattle 2 141
Firemonkey DbLookupComboBox equivalent ? 2 78
Delphi android app hide keyboard 3 82
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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
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…

738 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