How to encode subject content when sending mail with TIdMessage ?

CK CK 3788 
Created at
Updated at  
1,076 0 0

Today, I tried to develop mail application with TIdMessage, but I have problem in character set encoding. And I found the answer at http://www.yac.com.pl/mt.texts.tidmessage.charset.en.html

With this wrapper class, 

  TMyMessage = class(TIdMessage)
  private
    procedure InitializeUTF8(
                var VTransferHeader: TTransfer; var VHeaderEncoding: char; var VCharSet: string);
  end;
  
  procedure TMyMessage.InitializeUTF8(
    var VTransferHeader: TTransfer; var VHeaderEncoding: char; var VCharSet: string);
  begin
    VCharSet := 'UTF-8';
  end;


And then,

  LMessage := TMyMessage.Create(NIL);
  LMessage.ContentType := 'text/plain; charset=UTF-8';
  LMessage.OnInitializeISO := LMessage.InitializeUTF8;


Actually CharSet property of TIdMessage should work fine, but it doesn't work.

On Delphi 2009, some features are changed so you need to use below wrapper class as below.
 

  TMyMessage = class(TIdMessage)
  private
    procedure InitializeUTF8(
                var VHeaderEncoding: char; var VCharSet: string);
  end;

procedure TMyMessage.InitializeUTF8(
    var VHeaderEncoding: char; var VCharSet: string);
  begin
    VCharSet := 'UTF-8';
  end;


 

Tags Base64 Encode CharSet Mail Header Encoding Send Mail in UTF-8 UTF-8 Facebook X
Comments 0
Similar posts
  1. How to send text/html based email in UTF-8 with TIdSMTP, TIdMessage VCL
    1,084
  2. Delphi string conversion functions - AnsiToUTF-8, UTF8Encode, ...
    646
  3. How to send email by TIdSMTP VCL ?
    1,023
  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,098
  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. When subject is crashing in TIdSMTP VCL
    620
  16. Base64 Encoding/Decoding function for Delphi
    1,176
  17. How to return exit code such as exit() function in C/C++ ?
    670
  18. How to get parameter string ?
    1,249
  19. Save TBitmap image to Jpeg format image in Delphi
    717
  20. How to get screen resolution in case of using multiple monitors ?
    452
  21. How to turn off monitor ?
    435
  22. Find File at certain directory in Delphi
    441
  23. Sending email messages in .Net
    1,041
  24. Delphi for .Net Code Folding keyboard shortcuts
    530
  25. How to encrypt a string
    468
  26. Creating thumbnail images
    865
  27. Technology sharing related with software development. Specially content will be focused to programming language, and embedded systems.
    855
  28. How to speed up access to the RichTextBox Lines property
    832
  29. Window flashing
    379
  30. How to use TTF Font Without Installing
    1,122
Recently updated
  1. Google OAuth Token Expiration: Causes and Solutions
    29
  2. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    55
  3. Why SPF and DKIM Are Essential for Linux Email Servers?
    49
  4. How do I create animated background for Google Meet?
    22,861
  5. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    271
  6. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    103
  7. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    168
  8. Array of arguments passed to script in PHP
    97
  9. Invalid Auction Storms in Ad Tech
    106
  10. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    207
  11. The Two Clocks of Ad Server Architecture
    77
  12. Frequency Cap Architecture Overview
    526
  13. Collecting Proof-of-Play from 100,000 Screens
    152
  14. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    302
  15. What is RedisVL?
    114
  16. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    246
  17. TPU & GPU Cluster Management Tools
    257
  18. The Concept of Scaffolding in AI Agents
    244
  19. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    596
  20. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    267
  21. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    353
  22. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    206
  23. Machine Learning: Training vs. Ranking
    229
  24. The Continuous Learning Machine: Designing a Loop That Actually Turns
    228
  25. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    202
  26. Designing a Data Curation System Around a Vector Database
    230
  27. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    263
  28. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    671
  29. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    200
  30. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    232