Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Apr : Problems with TidSMTP

www.cryer.info
Managed Newsgroup Archive

Problems with TidSMTP

Subject:Problems with TidSMTP
Posted by:"mark horrocks" (markhorroc..@yahoo.com)
Date:Sun, 20 Apr 2008 17:21:26

I have been trying to make my ISAPI send email for awhile now but no
success. I can successfully get Outlook Express to send from my server via
my remote workstation with no problem. SMTP is setup to allow anymous
access. The error message I get from the code below is the class name:
EIdSMTPReplyError

This problem is really frustrating for me. Server is 2003 and D7 with Indy
10.

procedure TWebModule1.WebModule1waSendMailAction(Sender: TObject;
  Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
        SMTP: TIdSMTP;
        Email: TIdMessage;
        Msg: String;
begin
        try
            SMTP := TIdSMTP.Create(nil);
            try
                SMTP.Host := 'sportdata.com.au';
                SMTP.Port := 25; //smtp service usually runs on this port

                Email := TIdMessage.Create(nil);
                try
                    Email.From.Address :=
Request.ContentFields.Values['FromAddress'];
                    Email.Recipients.EMailAddresses :=
Request.ContentFields.Values['FromAddress'];
                    Email.BccList.EMailAddresses :=
Request.ContentFields.Values['EmailAddresses'];
                    Email.Subject :=
Request.ContentFields.Values['Subject'];
                    Email.ContentType := 'text/html';

                    if Request.ContentFields.Values['BodyText'] = '' then
                    Email.Body.Text := '<html><head></head><body>' + '<p>' +
                        Request.ContentFields.Values['AdditionalMessage'] +
                        '</body></html>'
                    else Email.Body.Text := '<html><head></head><body>' +
'<p>' +
                        Request.ContentFields.Values['AdditionalMessage'] +
                        Request.ContentFields.Values['BodyText'] +
                        '</body></html>';

                    SMTP.Connect;
                    try
                        SMTP.Send(Email);
                    finally
                        SMTP.Disconnect;
                    end;
                finally
                    Email.Free;
                end;
            finally
                SMTP.Free;
            end;
            Msg := 'Email(s) sent successfully!';
        except
            on E: Exception do
            begin
                Msg := E.Message;
                if Msg = '' then Msg := E.ClassName;
            end;
        end;
        Response.Content := '<html><head></head><body><p><h3>' + Msg +
'</h3></body></html>';
    end;

Mark Horrocks

Replies:

www.cryer.info
Managed Newsgroup Archive