procedure SetAddress( AList : TIdEmailAddressList ; AStr : string);
var
nStrList : TStringList;
nCnt : integer;
nItem : TIdEMailAddressItem;
begin
AList.Clear;
nStrList := TStringList.Create;
try
nStrList.CommaText := AStr;
for nCnt := 0 to nStrList.Count - 1 do
begin
nItem := AList.Add;
nItem.Address := Trim(nStrList.Strings[nCnt])
end;
finally
nStrList.Free;
end;
end;
begin
nDate := FormatDateTime('yyyy-mm-dd', now);
nTime := FormatDateTime('hh:mm', now);
idSMTP.Host := fMailHost;
idSMTP.Port := fMailPort; //smtp service usually runs on this port
IdSMTP.Username := fMailUserName;
idSMTP.Password:=fMailUserPwd;
idmessage.From.address:= fGMSHFromAddress;
// 첨부파일 넣기 (실제 파일 GetExcelFile)
nAttFileName := 'c:\a.xls';
if nAttFileName <> '' then
begin
LTheAttachment := TIdAttachmentFile.Create(idmessage.MessageParts, nAttFileName);
end;
//with IdMessage do DoCreateAttachment(attachment.Headers, attachment);
try
try
idSMTP.Connect;
except on E: Exception do
begin
Log := 'Mail connect Error : ' + E.Message;
end;
end;
try
idSMTP.send(idmessage);
//if an exception occurs?/span>
except on E: Exception do
begin
Log := 'Send Mail Error : ' + E.Message;
end;
end;
finally
//disconnect from server
if IdSMTP.Connected then
IdSMTP.Disconnect;
end;
// end;
end;
제가 사용했던부분인데.. 될겁니다.
var
nDate, nTime : string;
nAttFileName : string;
LTheTextPart: TIdText;
LTheAttachment: TIdAttachmentFile;
nSubject : string;
nItem : TIdEMailAddressItem;
procedure SetAddress( AList : TIdEmailAddressList ; AStr : string);
var
nStrList : TStringList;
nCnt : integer;
nItem : TIdEMailAddressItem;
begin
AList.Clear;
nStrList := TStringList.Create;
try
nStrList.CommaText := AStr;
for nCnt := 0 to nStrList.Count - 1 do
begin
nItem := AList.Add;
nItem.Address := Trim(nStrList.Strings[nCnt])
end;
finally
nStrList.Free;
end;
end;
begin
nDate := FormatDateTime('yyyy-mm-dd', now);
nTime := FormatDateTime('hh:mm', now);
idSMTP.Host := fMailHost;
idSMTP.Port := fMailPort; //smtp service usually runs on this port
IdSMTP.Username := fMailUserName;
idSMTP.Password:=fMailUserPwd;
idmessage.From.address:= fGMSHFromAddress;
SetAddress(IdMessage.Recipients, fGMSHRecipientsAddress);
SetAddress(idmessage.CCList, fGMSHCCAddress);
//idmessage.BccList.EMailAddresses:=edBC.Text;
IdMessage.ConvertPreamble := False;
IdMessage.ContentType := 'multipart/mixed';
IdMessage.Encoding := meMIME;
IdMessage.ContentTransferEncoding := '8bit';
IdMessage.CharSet := 'KS_C_5601-1987';
IdMessage.Date := now;
// idmessage.ContentType:='text/plain' ;
nSubject := format (
'테스트 메일입니다. . %s일 .' , [nDate]);
idmessage.Subject := EncodeHeader(nSubject, [], 'B' , bit8, IdMessage.CharSet);
// idmessage.Subject := EncodeHeader(nSubject, '', 'B' , bit8, IdMessage.CharSet);
//중요도
IdMessage.Priority := mpHigh;
idmessage.MessageParts.Clear;
LTheTextPart := TIdText.Create(idmessage.MessageParts);
LTheTextPart.Body.Text := Format(' 테스트입니다. '+#10#13+' %s %s 데이터 수신 현황입니다.'+
#10#13+
' 감사합니다. ', [nDate, nTime]);
LTheTextPart.ContentTransfer := '8bit';
LTheTextPart.ContentType := 'text/plain';
LTheTextPart.charset := 'KS_C_5601-1987';
LTheTextPart.ParentPart := -1;
// 첨부파일 넣기 (실제 파일 GetExcelFile)
nAttFileName := 'c:\a.xls';
if nAttFileName <> '' then
begin
LTheAttachment := TIdAttachmentFile.Create(idmessage.MessageParts, nAttFileName);
end;
//with IdMessage do DoCreateAttachment(attachment.Headers, attachment);
try
try
idSMTP.Connect;
except on E: Exception do
begin
Log := 'Mail connect Error : ' + E.Message;
end;
end;
try
idSMTP.send(idmessage);
//if an exception occurs?/span>
except on E: Exception do
begin
Log := 'Send Mail Error : ' + E.Message;
end;
end;
finally
//disconnect from server
if IdSMTP.Connected then
IdSMTP.Disconnect;
end;
// end;
end;