Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8122701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:54:55+00:00 2026-06-06T05:54:55+00:00

I try to send an email, but I have a problem, however, I found

  • 0

I try to send an email, but I have a problem, however, I found this code on the web:

Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdMessage, IdTCPConnection, IdTCPClient,
IdMessageClient, IdSMTP, IdBaseComponent, IdComponent, IdIOHandler,
IdExplicitTLSClientServerBase, IdSMTPBase

procedure SendSimpleMail;
var
Msg: TIdMessage;
DestAddr: TIdEmailAddressItem;
begin
Msg := TIdMessage.Create(Self); //error here
Msg.From.Text := 'name';
Msg.From.Address := 'username@gmail.com';
Msg.Subject := 'Test';

DestAddr := Msg.Recipients.Add;
DestAddr.Text := 'name';
DestAddr.Address := 'username@yahoo.com';
Msg.Body.Add('simple test mail.');

tIdSMTP.Host := 'smtp.gmail.com';
tIdSMTP.Port := 25;
tIdSMTP.AuthenticationType := atLogin; //error here (2 error)
tIdSMTP.Username := 'username@gmail.com';
tIdSMTP.Password := 'password';
tIdSMTP.Connect;
tIdSMTP.Authenticate;
tIdSMTP.Send(Msg);
tIdSMTP.Disconnect;
end;

But however, I noted many mistakes and I am missing a component of Indy.
Compiler errors:

[DCC Error] Unit1.pas(36): E2003 Undeclared identifier: 'Self'
[DCC Error] Unit1.pas(46): E2233 Property 'Host' inaccessible here
[DCC Error] Unit1.pas(47): E2233 Property 'Port' inaccessible here
[DCC Error] Unit1.pas(48): E2003 Undeclared identifier: 'AuthenticationType'
[DCC Error] Unit1.pas(48): E2003 Undeclared identifier: 'atLogin'
[DCC Error] Unit1.pas(49): E2233 Property 'Username' inaccessible here
[DCC Error] Unit1.pas(50): E2233 Property 'Password' inaccessible here
[DCC Error] Unit1.pas(51): E2076 This form of method call only allowed for class methods
[DCC Error] Unit1.pas(52): E2076 This form of method call only allowed for class methods
[DCC Error] Unit1.pas(53): E2076 This form of method call only allowed for class methods
[DCC Error] Unit1.pas(54): E2076 This form of method call only allowed for class methods
[DCC Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'

Thanks for the help in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:54:56+00:00Added an answer on June 6, 2026 at 5:54 am

    The code from your question is written for Indy 9 and from your compiler error seems you’re using Indy 10. To your compiler errors:

    • Undeclared identifier: Self – the Self is the pointer to the class instance itself and since you didn’t write the SendSimpleMail as a class method but just as a standalone procedure, you don’t have any Self just because you don’t have any class. The class method you could write for instance for your form class like e.g. TForm1.SendSimpleMail, where inside of that method the Self would have meaning of the TForm1 instance, the form itself.

    • And the rest of the errors you got because you were accessing the TIdSMTP class, not the object instance. Commonly used practice is to declare a local variable, create an object instance assigning it to that variable, work with that object (variable) and free the object instance.

    I would try something like this (tested with Indy 10 shipped with Delphi 2009):

    uses
      IdSMTP, IdMessage, IdEMailAddress;
    
    procedure SendSimpleMail;
    var
      IdSMTP: TIdSMTP;
      IdMessage: TIdMessage;
      IdEmailAddressItem: TIdEmailAddressItem;
    begin
      IdSMTP := TIdSMTP.Create(nil);
      try
        IdSMTP.Host := 'smtp.gmail.com';
        IdSMTP.Port := 25;
        IdSMTP.AuthType := satDefault;
        IdSMTP.Username := 'username@gmail.com';
        IdSMTP.Password := 'password';
        IdSMTP.Connect;
        if IdSMTP.Authenticate then
        begin
          IdMessage := TIdMessage.Create(nil);
          try
            IdMessage.From.Name := 'User Name';
            IdMessage.From.Address := 'username@gmail.com';
            IdMessage.Subject := 'E-mail subject';
            IdMessage.Body.Add('E-mail body.');
    
            IdEmailAddressItem := IdMessage.Recipients.Add;
            IdEmailAddressItem.Address := 'recipient@email.com';
    
            IdSMTP.Send(IdMessage);
          finally
            IdMessage.Free;
          end;
        end;
        IdSMTP.Disconnect;
      finally
        IdSMTP.Free;
      end;
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used this code to send mails but I am not getting any
I have code to send email using Exchange Web Services (EWS 1.1 API). There
I have some code used to send emails. It works on windows but when
i have downloaded Swift Mailer from their website and try to send simple email
I am trying to send email using c# following is my code. try {
I'm working with Perl on Windows. I will try to send mail with Email::Sender
i have a problem with this intent. this intent is supose to send a
I have an application that uses SmtpClient to send E-Mail, but the E-Mails are
I have written some simple code, to send en auto generated email, using the
I have PHP and Postfix installed. So if i try to send an email

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.