TidMessage 와 TIdText의 CharacterSet을 설정하시면 됩니다.
TextMessage:= TIdText.Create(MailMessage.MessageParts, nil);
TextMessage.Body.Text:= DecodeUTF8(Content);
TextMessage.ContentType:= 'text/plain';
TextMessage.CharSet:= 'euc-kr';
UTF-8이나 euc-kr로 설정하세요.
dll에서 UTF-8 문자로 Indy를 사용할 때 TidMessage의 Subject 문자가 깨지는 문제가 발생하더군요.
간단한 메일이면 Alcinoe 컨포넌트를 사용하시면 됩니다. Free Component 구요.
준초보 님이 쓰신 글 :
: Delphi 2009 indy 10.2.5 에서 smtp 로 메일을 보내려구 합니다.
:
: 제가 궁금한 부분은 한글처리 부분입니다
:
: 아래와 같이 코딩했는데 깨지는 현상이 일어납니다. 인터넷에 아무리 돌아다녀도 답을 못찾겠네요
:
: 아시는분 조언좀 부탁드립니다.
:
:
: ===========================================================
: function StrToBytes(text: string; codePage: Word): TBytes;
: begin
: case codePage of
: 0: Result := TEncoding.Default.GetBytes(text);
: 1200: Result := TEncoding.Unicode.GetBytes(text);
: 1201: Result := TEncoding.BigEndianUnicode.GetBytes(text);
: 20127: Result := TEncoding.ASCII.GetBytes(text);
: 65000: Result := TEncoding.UTF7.GetBytes(text);
: 65001: Result := TEncoding.UTF8.GetBytes(text);
: else
: begin
: if codePage = GetACP() then begin
: Result := TEncoding.Default.GetBytes(text);
: end else
: begin
: with TEncoding.GetEncoding(codePage) do
: try
: Result := GetBytes(text);
: finally
: Free;
: end;
: end;
: end;
: end;
: end;
:
:
: with IdMessage do
: begin
: Clear;
: ClearBody;
: MessageParts.Clear;
: ClearHeader;
: ContentType := 'text/html';
: CharSet := 'ks_c_5601-1987';
: Headers.Add('Content-type: text/html');
: Encoding := meMIME;
:
: Bytes := StrToBytes('가나다라마바사', 65001);
: From.name := BytesToString(Bytes);
: Subject := BytesToString(Bytes,enUTF8);
: Body.Text := BytesToString(Bytes);
:
: ReplyTo.EMailAddresses := edtTo.Text;
: Recipients.EMailAddresses := edtTo.Text; { To: header }
:
: Priority := TIdMessagePriority(cboPriority.ItemIndex); { Message Priority }
: if chkReturnReciept.Checked then
: begin {We set the recipient to the From E-Mail address }
: ReceiptRecipient.Text := From.Text;
: end
: else
: begin {indicate that there is no receipt recipiant}
: ReceiptRecipient.Text := '';
: end;
: end;
|