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;
|