How to send email by TIdSMTP VCL ?

CK CK 3788 
Created at  
1,023 0 0
TIdSMTP component is very useful VCL in Delphi 2009. Here's the simple example to send email.

uses IdSMTP, IdMessage;;

procedure KMAIL( sTo, title, body:string);
var
  IdMsg : TIdMessage;
begin
  IdMsg := TIdMessage.Create(nil);
  try
    with TIdSMTP.Create(nil) do
    try
      UserName := SMTPFrm.m_username.Text;
      Password := SMTPFrm.m_password.Text;
      Host := SMTPFrm.m_host.Text;
      IdMsg.Body.Add(body);
      IdMsg.Recipients.emailAddresses := sTo;
      IdMsg.Subject := title;
      IdMsg.From.Address := SMTPFRm.m_email.Text;
      IdMsg.From.Name := SMTPFRm.m_realname.Text;
      Connect;
      Send(IdMsg);
      Disconnect;
    finally
      Free;
    end;
  finally
    IdMsg.free;
  end;
end;

procedure TMainFrm.Button1Click(Sender: TObject);
begin
  KMAIL( 'foo@foo.com', 'Test mail from kurapa', 'Man, this is test mail from kurapa!!');
end;

As you can see above, you need Host, User ID, Password for sending email. In addition, you can define SMTP port as well.
Tags CharSet ContentType MIME Type Encoding SMTP SmtpServer TIdMessage TIdSMTP Facebook X
Comments 0
Similar posts
  1. How to encode subject content when sending mail with TIdMessage ?
    1,075
  2. How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL
    1,084
  3. When subject is crashing in TIdSMTP VCL
    620
  4. Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ...
    645
  5. Sending email messages in .Net
    1,041
  6. Send An Email Using A Bean
    1,020
  7. Send Email Using C#
    1,380
  8. How To Send An E-mail By Code
    1,124
  9. Set up an SMTP server on CentOS 7
    730
  10. Bash script to install postfix and sasl for sending email
    1,200
  11. Why SPF and DKIM Are Essential for Linux Email Servers?
    49
  1. I want to select directory(folder) not file. How can I do that ?
    624
  2. Changing the Title of a Print Dialog in Delphi
    1,098
  3. Auto Logon Programming in Delphi
    1,033
  4. Thread Application Implementation in TThread
    670
  5. Is there directory selection VCL component in Delphi ?
    523
  6. How to launch the external application in Delphi ?
    1,074
  7. How to print external document ?
    423
  8. Delphi API to get windows temporary directory
    586
  9. Delphi API to get the current working directory
    1,254
  10. How to resize PNG file in Delphi ?
    1,223
  11. Get the length of arrays and a string
    1,742
  12. Delphi Pointer Types
    22,097
  13. How to read/wrtie INI file in Delphi ?
    3,123
  14. How to get file created time, modified time, and last accessed time ?
    3,348
  15. Base64 Encoding/Decoding function for Delphi
    1,176
  16. How to return exit code such as exit() function in C/C++ ?
    670
  17. How to get parameter string ?
    1,249
  18. Save TBitmap image to Jpeg format image in Delphi
    717
  19. How to get screen resolution in case of using multiple monitors ?
    452
  20. How to turn off monitor ?
    435
  21. Find File at certain directory in Delphi
    441
  22. Delphi for .Net Code Folding keyboard shortcuts
    530
  23. How to encrypt a string
    468
  24. Creating thumbnail images
    865
  25. Technology sharing related with software development. Specially content will be focused to programming language, and embedded systems.
    855
  26. How to speed up access to the RichTextBox Lines property
    832
  27. Window flashing
    379
  28. How to use TTF Font Without Installing
    1,122
  29. How to show window contents while dragging
    461
  30. How to save text from Clipboard to a file
    573
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    28
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    55
  3. How do I create animated background for Google Meet?
    22,830
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    271
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    103
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    168
  7. Array of arguments passed to script in PHP
    97
  8. Invalid Auction Storms in Ad Tech
    106
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    207
  10. The Two Clocks of Ad Server Architecture
    77
  11. Frequency Cap Architecture Overview
    526
  12. Collecting Proof-of-Play from 100,000 Screens
    152
  13. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    302
  14. What is RedisVL?
    114
  15. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    246
  16. TPU & GPU Cluster Management Tools
    257
  17. The Concept of Scaffolding in AI Agents
    244
  18. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    596
  19. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    267
  20. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    353
  21. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    206
  22. Machine Learning: Training vs. Ranking
    229
  23. The Continuous Learning Machine: Designing a Loop That Actually Turns
    228
  24. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    202
  25. Designing a Data Curation System Around a Vector Database
    230
  26. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  27. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    671
  28. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    200
  29. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    232
  30. Understanding Data Lineage
    271